




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





















Lesson Outline
Features of Python
Basic rules in Python
Standard Data Types Python has five standard data types:
Operators & Operands
Comparison Operators
Operator Description Example == Checks if the value of two operands are equal or not, if yes then condition becomes true. (a == b) is not true. != Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. (a != b) is true. <> Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. (a <> b) is true. This is similar to != operator. > Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (a > b) is not true. < Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (a < b) is true. >= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (a >= b) is not true. <= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (a <= b) is true.
Assignment Operators Operator Description Example = Assigns values from right side operands to left side operand c = a + b will assign value of a + b into c += It adds right operand to the left operand and assign the result to left operand c += a is equivalent to c = c + a
- = It subtracts right operand from the left operand and assign the result to left operand c - = a is equivalent to c = c – a = It multiplies right operand with the left operand and assign the result to left operand c = a is equivalent to c = c * a /= It divides left operand with the right operand and assign the result to left operand c /= a is equivalent to c = c / a %= It takes modulus using two operands and assign the result to left operand c %= a is equivalent to c = c % a ****= Performs exponential (power) calculation on operators and assign value to the left operand c **= a is equivalent to c = c ** a //= Performs floor division on operators and assign value to the left operand c //= a is equivalent to c = c // a
Operator Example x= y= print("x =",x) print("y =",y) print("x + y =",x+y) print("x - y =",x-y) print("x * y =",xy) print("x / y =",x/y) print("x % y =",x%y) print("x // y =",x//y) print("x ** y =",xy) x += y print("After x+=y, now x =",x) p= q= print() print("With p=",p,"and q=",q,"Some Bitwise and Logical operators") print("p >> 2 =",p>>2) print("p << 3 =",p<<3) print("p & q",p&q) print("p | q",p|q) print("p ^ q",p^q) print("x!=y and p>8",x!=y and p>8) print("x!=y or p>8",x!=y or p>8) print("not p==8",not p==8)*
Control Constructs
Continue keyword
Find the output
for val in "string": if val == "i": break print(val) print("The end")
Else in Loops ( Find the output ) x = 1 while x<= 5 : print(x) x = x + 1 else: print(“The end value of x = “,x) print(“** The End **”)
Else in Loops ( Find the output ) x = 1 while x<= 5 : print(x) x = x + 1 else: print(“The end value of x = “,x) print(“** The End **”)