Python Variables
Naming your Variables
Statement is an instruction to the Interpreter
Expressions are combination of variables,values,statements,and operators that forces the interpreter to evaluate it.
| Operator | Description |
| + | Addition Operator |
| - | Subtraction Operator |
| / | Division Operator |
| // | Integer divsion Operator |
| % | Remainder Operator |
| ** | Exponentiation Operator |
Python 3.10.5 (main, Jun 9 2022, 00:00:00) [GCC 11.3.1 20220421 (Red Hat 11.3.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> i=2;j=3
>>> 2+3
5
>>> i+j
5
>>> i-j
-1
>>> i*j
6
>>> i/j
0.6666666666666666
>>> i//j
0
>>> i%j
2
>>> i**j
8
>>>
| Operator | Description |
| and | |
| or | |
| not | |
| Operator | Description |
| | | |
| & | |
| ^ | |
| >> | |
| << |
| Operator | Description |
| < | |
| > | |
| >= | |
| <= | |
| == | |
| != | |
| Operator | Description |
| op1*=op2 | op1 operand 1,op2 operand 2 op1*=op2, op1 is multiplied by op2, result is assigned to op1. x*=5 <==> x=x*5 |
| op1/=op2 | op1/=op2, op1 is divided by op2, result(Quotient) is assigned to op1. x/=5 <==> x=x/5 |
| op1%=op2 | op1/=op2, op1 is divided by op2, result(remainder) is assigned to op1. x%=5 <==> x=x%5 |
| op1+=op2 | op1+=op2, op1 is Added to op2, result is assigned to op1. x+=5 <==> x=x+5 |
| op1-=op2 | op1-=op2, op1 is substracted from op2, result is assigned to op1. x-=5 <==> x=x-5 |
Ternary Operators are very famous in Other Programming languages like C,C++, & Java. neste In Python syntax is little different compared to other programming languages.
Syntax:[evaluate on True] if condition else [evaluate on False]
Condition is evaluated first, condition is True returns [evaluate on True] , Condition is False , [evalate on False] will be returned
>>>a=20 >>>b=30find max value using ternary operator
>>> a if ( a > b ) else b 30find max value from 3 values
>>>a=10;b=20;c=5 >>> a if (a>b and a>c) else b if (b > c) else c 20