Python Suresh Techs
Suresh techs
Operators
Suresh techs – Technology and Entertainment
Subscribe Doubts
Suresh Techs
Subscribe: You don’t miss our Follow In Instagram
future videos #sureshtechs
• Link in the description
• Clear your doubts chatting with me
TV Repair
• Cable operator
Suresh Techs
Python programming operations
Suresh Techs
a,b,c are operands
+, = are operators
Operators
• Are used to perform various operations on values and variables
Suresh Techs
Different Operators
• Arithmetic
• Relational operators(Comparison)
• Assignment
• Logical Suresh Techs
• Bitwise
While discussing input-output
• Fancier outputs:
• format() method
Suresh Techs
format() method on print function
• What if I wanted to print “Take your cash 1000, balance in your
account is 49000”?
• Let’s use format() method
Suresh Techs
Will see more examples soon
Arithmetic operators
Operator Description Syntax
+ Adds two operands a+b
- Subtracts two operands a-b
* Multiplies two operands a*b
/ Suresh Techs
Divides the first operand by second (float) a/b
// Divides the first operand by second (floor) a//b
% Returns the reminder when first operand is divided by a%b
second
** Returns first to the power of second a**b
Relational operators
• Returns either True or False
Operator Description Syntax
== True if both operands are equal a==b
> Suresh Techs
True if left operand is greater than right
a>b
< True if left operand is less than right a<b
>= True if left operand is greater than or equal a>=b
to right operand
<= True if left operand is less than or equal to a<=b
right operand
!= Not equal to: True if the operands are not a!=b
equal
Program
Suresh Techs
Logical operators
Operator Description Syntax
and True if both the operands are true a and b
Or True if one of the operand is true a or b
not True if operand is false, vice versa not a
Suresh Techs
Program
Suresh Techs
Bitwise operators
Operator Description Syntax
& Bitwise AND a&b
| Bitwise OR a|b
~ Bitwise NOT ~a
^ Suresh Techs
Bitwise XOR a^b
>> Bitwise right shift a>>
<< Bitwise left shift a<<
Note: Will be discussed later in the advanced course
Assignment operators
Operator Description Syntax
= Assign right side expression to left side operand a = b+c
+= AddAnd – Adds right side operand with left side operand a+=b
and then assign it to left side operand a=a+b
-= SubtractAnd – Subtracts right side operand from left side a-=b
Suresh Techs
operand and then assign it to left side operand a=a-b
*= MultiplyAnd – Multiplies right side operand with the left a*=b
side operand and then assign it to the left side operand a=a*b
Similarly for other operators:
a/=b a%=b a//=b a**=b a&=b a|=b a^=b a>>=b a <<= b
a=a/b a=a%b a=a//b a=a**b a=a&b a=a|b a=a^b a=a>>b a= a << b
Program Suresh Techs
Few more
• Identity operators(is, is not)
• Membership operators(in, not in)
• Ternary operator(true?something : somethingelse )
Suresh
• Python: [on_true] if [expression] elseTechs
[on_false]
• Will talk about them later
Program for you (try on your own)
• Find age of the person by asking birth year
Suresh Techs
Program for you (try on your own)
• But this code will only work in this year
• Will use datetime library
• from datetime import date
Suresh Techs
Suresh techs – Technology and Entertainment
Subscribe Doubts
Suresh Techs
Subscribe: You don’t miss our Follow In Instagram
future videos #sureshtechs
• Link in the description
• Clear your doubts chatting with me
Suresh Techs