484647789 by Unknown

484647789 by Unknown

Author:Unknown
Language: eng
Format: epub


In the following example, the loop continues if the number is 0 but stops (break) if it is 5, so we get 1 2 3 4.

n = list(range(10))

for x in n:

if x == 5: break

elif x == 0 : continue

else: print(x)

The “While” keyword also creates a loop, which break only if the condition is false. This may create a perpetual loop if the condition is always true.

n = 10

while n:

print(n)

n = n-1

In the above example, the while keyword evaluates the number to check if it is True, i.e. not 0 or None, print the number and reduce it by 1.Notice that any object in Python is True, except False, None or Zero.

The "and", "or" , "not" Keywords

Those logical operators are used with the “if” and other conditional statements to compare expressions against given conditions.

And : executes an expression if both the operands are true

Or : executes an expression if either of the operands is true

Not : executes an expression if an operand is false

Here is an example of using the three keywords:

Username = "Suresh"



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.