Class - VIII Chapter - 9 and 10 Python Language Notes:: Print ("Hello, World!") Hello, World!
Class - VIII Chapter - 9 and 10 Python Language Notes:: Print ("Hello, World!") Hello, World!
Chapter - 9 and 10
PYTHON LANGUAGE
NOTES:
Python is a popular programming language. It was created by Guido van Rossum, and released
in 1991.
It is used for:
Creating a Comment
x=5
y = "John"
print(x)
print(y)
x = str(3)
y = int(3)
z = float(3)
print(x)
print(y)
print(z)
Variable Names
A variable can have a short name (like x and y) or a more descriptive name (age, carname,
total_volume). Rules for Python variables:
myvar = "John"
my_var = "John"
print(myvar)
print(10 > 9)
print(10 == 9)
print(10 < 9)
Python divides the operators in the following groups:
Arithmetic operators
Assignment operators
Comparison operators
Logical operators
Identity operators
Membership operators
Bitwise operators
Equals: a == b
Not Equals: a != b
Less than: a < b
Less than or equal to: a <= b
Greater than: a > b
Greater than or equal to: a >= b
These conditions can be used in several ways, most commonly in "if statements" and loops.
a = 33
b = 200
if b > a:
print("b is greater than a")
a = 33
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
a = 200
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
else:
print("a is greater than b")
Python Loops
while loops
for loops
With the while loop we can execute a set of statements as long as a condition is true.
WHILE LOOP
i=1
while i < 6:
print(i)
i += 1
The break Statement
With the break statement we can stop the loop even if the while condition is true:
i=1
while i < 16:
print(i)
if (i == 10):
break
i += 1
With the continue statement we can stop the current iteration, and continue with the next:
Example
With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.
Example
_____________________________________________________