SlideShare a Scribd company logo
OPERATORS IN PYTHON
Contents
Operator
Operator precedence and Associativity
Mathematical Functions
operator
An operator is a symbol that performs operation. Operator acts on
variables or constants known as operands. If operator acts on single
operand then it is called as unary and if acts on two operands then it is
called as binary and when acts on three operands it is called as ternary
operator.
Operators are classified depending upon their nature as..
Classification of operators
arithmetic
assignment
unary minus
relational
 logical
 Boolean
 bitwise
 membership
 Identity
Arithmetic operator
performs basic arithmetic operation like addition, subtraction, multiplication and division.
Lets assume a=13 and b=5
operator Meaning Example Result
+ addition a+b 18
- subtraction a-b 8
* multiplication a*b 65
/ division a/b 2.6
% Modulus(remainder) a%b 3
** Exponent operator a**b 371293
// Integer division a//b 2
TEST1
Writes a python program to perform all arithmetic operations on two variable
a=20 and b=6
Priority to arithmetic operators
1.parentheses
2.exponent
3.multiplication,division,modulus and floor division are at equal priority
4.Addition and subtraction
5.Assignment
Evaluate the following arithmetic expression
d=(1+2)*3**2//2+3
Assignment Operator
stores the right side value to left side variable. Short hand assignments operators
used to perform arithmetic operations and stores the result to left side variable.
X=20, y=10 and z=5
Operator Example Meaning Result
= z=x+y Assignment operator z=30
+= z+=x
(z=z+x)
Shorthand addition
assignment operator
z=25
-= z-=x
(z=z-x)
Shorthand subtraction
Assignment operator
z=-15
*= z*=x
z=z*x
Shorthand
multiplication operator
z=100
/= z/=x
z=z/x
Shorthand division
operator
Z=0.25
%= z%=x
z=z%x
Shorthand modulus
operator
Z=5
**= z**=y
z=z**y
Shorthand Exponent
assignment operator
Z=9765625
//= z//=y
z=z//y
Shorthand division
assignment operator
0
Contd..
TEST2
Write python program to perform arithmetic operation on x=“20”
and y=0xad using shorthand assignment operator
Guess the output
a=b=1
print(a,b)
a=1;b=2
print(a,b)
a,b=1,2
print(a,b)
Note: python does not support increment(++) and decrement operator
Unary Minus Operator
The symbol – is used as unary minus operator. This operator is used
before a variable, its value is negated. That means if the variable value
is positive, it will be converted into negative and vice versa.
Example:
N=10
print(-N) output: -10
Num=-10
Num=-Num
print(Num) output: 10
Relational Operators
these operators are used for comparison of values. They returns Boolean value True or False.
a=1 and b=2
Operator Example Meaning Result
> a>b Greater than operator False
>= a>=b Greater than or equal to
operator
False
< a<b Less than operator True
<= a<=b Less than or equal to True
== a==b Equals to operator False
!= a!=b Not equals operator True
Contd..
Relational operators can be chained. It means a single expression can
hold more than one relational operators
Guess the output
x=15
print(10<x<20)
print(10>=x<20)
print(1<2<3<4)
print(1<2>3<4)
print(4>2>=2>1)
Logical operator
Logical operators are used to construct compound condition. A
compound condition is a combination of more than one simple
condition. Each of the simple condition is evaluated to True or False and
then the decision is taken to know whether total condition is True or
False. a=10,b=20,c=3,d=5
operator Example Meaning Result
and a>b and c>d Logical and False
or a>b or c<d Logical or True
not not a>b Logical not True
Boolean Operators
There are three Boolean operators which results True or False.
x=True y=False
operator Example meaning result
and x and y If both are true
then it returns true
otherwise false
False
or x or y If either x or y is
True then it returns
True else False
True
not not x If x is True it returns
False else True.
False
Guess the output
x=10; y=0
print(x and y) # if x and y both evaluated as true then y is returned true
# if x is true and y is false then y is returned
print(x or y)
print(not x)
print(not y)
OUTPUT
0
10
False
True
Bitwise operator
operates on individual bits ( 0 and 1) of the operands. They can operates on binary
number or integers.
Complement operator(~)
AND operator(&)
OR operator(|)
XOR operator(^)
Left shift operator(<<)
Right shift operator(>>)
Contd..
Complement of given number is returned by toggling the bits.
Example:
x=10
X=10=0000 1010
print(~x,bin(~x))
print(~b,bin(~b))
Output
-11 ( 1111 0101)
AND Operator(&)
x=10=0000 1010
y=11=0000 1011
x&y=0000 1010 (10)
example
x=10; b=15
print(x & b, bin(x &b))
x=0b1001;x=0b1001
print( x & b, bin( x & b) )
Output:
Bitwise OR Operator(|)
x=10=0000 1010
y=11=0000 1011
X|y=0000 1011 (15)
example
x=10;b=15
print(x | b, bin(x | b))
x=0b1001;b=0b1001
print( x | b, bin( x | b) )
Output
15 0b1111
9 0b1001
Bitwise XOR Operator(^)
x=10=0000 1010
y=11=0000 1011
x&y=0000 0001 (15)
Example
x=10
b=15
print(x ^ b, bin(x ^b))
x=0b1001
b=0b1001
print( x ^ b, bin( x ^b) )
Output
5 0b101
0 0b0
Bitwise left shift operator(<<): shifts the bits of the number
towards left specified number of positions.
x=10
X<<2
0 0 0 0 1 0 1 0
0 0 0 1 0 1 0 0 ( first time shift)
0 0 1 0 1 0 0 0 ( second time shift) (40)
Example
x=10
print(x<<2, bin(x<<2))
x=0b1001
print(x<<1,bin(x<<1))
Output
40 0b101000
Bitwise right shift operator(>>): shifts the bits of
the number towards right specified number of positions.
x=10
X>>2
0 0 0 0 1 0 1 0
0 0 0 0 0 1 0 1 ( first time shift)
0 0 0 0 0 0 1 0 ( second time shift) (2)
Example
x=10
print(x>>2, bin(x>>2))
x=0b1001
print(x>>1,bin(x>>1))
Output
2 0b10
4 0b100
Membership operators: to test a member is in
sequence such as list, string, tuple and dictionary
in operator: it returns True if an element is found in specified sequence otherwise returns False.
Example:
City=[‘Belagum’, ‘Bombay’, ’Mysore’ , ‘Lucknow’]
for k in City:
print(k)
If ‘Mysore’ in City:
print(“yes”)
else:
print(“no”)
Output
Belagum
Bombay
Mysore
Lucknow
yes
Contd..
not in operator: Works in reverse manner for in operator. This operator
returns True if an element is not found in the sequence
City=["Belagum" , "Bombay" , "Mysore" , "Lucknow"]
if "Mysore" not in City:
print("yes")
else:
print("no")
Output:
no
Identity Operator
The memory location of object can be seen using the id() function. This
function returns an integer number called the identity number that
internally represents the memory location of the object.
a=25
b=25
print(id(a),id(b))
b=47
print(id(a),id(b))
Output
140731879209504 140731879209504
140731879209504 140731879210208
The is operator
is operator compare whether two objects identity numbers are same or not. If
same it returns True otherwise False.
a=25
b=25
if a is b:
print("Both have same identity")
else:
print("They do not have same identity")
Output
Both have same identity
is not operator
If the identity numbers of two objects being compared are not same then it
returns True otherwise False.
a=25
b=35
if a is not b:
print("They do not have same identity")
else:
print("Both have same identity")
Output
They do not have same identity
Operator precedence and associativity
operator Name
() Parenthesis
** Exponentiation
-,~ Unary minus, bitwise complement
*, /,//,% Multiplication, division, floor division, modulus
+,- Addition, subtraction
<<,>> Bitwise left shift, bitwise right shift
& Bitwise AND
^ Bitwise XOR
| Bitwise OR
>,>=,<,<=,==,!= Relational operators
Contd..
Operator Meaning
=, %=,/=,//=,-=,+=,*=,**= Assignment operators
Is, is not Identity operators
In, not in Membership operator
not Logical not
or Logical or
and Logical
Associativity: In an expression if we have more than one operators with same
priority then we have to flow the associativity of a operator. Associativity operator
is either from left to right or right to left. All operators have the associativity from
left to right except assignment operator.
Expression evaluation
Value=3/2*4+3+(10/4)**3-2
Ans: 22.625
ValueAns:12
Value = 23<45 and 67-89>-10
Ans: False
Value=15<<3 + 65//6-7**2 or 8%2
Ans: ValueError: negative shift count
Value=not 78/4+(5-2)
Ans:False
Mathematical Functions
Functions Description
ceil(x) Raises x value to the next higher integer. If x is integer then same value is returned
ceil(4.5) gives 5
floor(x) Decreases x value to the previous integer value. If x is integer then the same value is
returned. floor(4.5) gives 4
degree(x) Converts angle value x from radians into degrees
degree(3.142) gives 179.999
radians(x) Converts x value from degrees into radians
radians(180) gives 3.142
sin(x) Gives sine value of x. Here x value is given in radians.
sin(0.5) gives 0.4794
cos(x) Gives cosine value of x. Here x value is given in radians.
cos(0.5) gives 0.87758
tan(x) Gives tangent value of x. Here x value is given in radians.
tan(0.5) gives 0.5463
exp(x) returns exponentiation of x. This is same as e **x
exp(0.5) returns 1.64872
Function Description
fabs(x) Gives the absolute value of x
fabs(-4.56) gives 4.56
factorial(x) Returns factorial value of x. Raises value error if x is not integer or is negative
factorial(4) gives 24
fmod(x,y) Returns remainder of division of x and y. fmod() is preferred to calculate modulus
for float values than % operator. It works well for integer values.
fmod(14.5,3) gives 2.5
fsum(values) Returns accurate sum of floating point values
fsum([1.5,2.4,-3.3]) returns 0.6000
modf(x) Returns float and integral part of x
modf(2.56) gives(0.56,2.0)
Log10(x) Returns logarithm of x for base 10
Log10(5.2345) gives 0.71888
Log(x,[base]) Returns the natural logarithm of x of specified base
log(5.5,2) gives 2.45943
Sqrt(x) Returns positive square root value of x
Sqrt(49) gives 7
Function Description
pow(x,y) Raises x value to the power of y
pow(5,3) returns 125.0
gcd(x,y) Gives greatest common divisor of x and y. Available from
python 3.5 onwards
gcd(25,30) gives 5
trunc(x) The real value of x is truncated to integer value and returned
trunc(15.5676) gives 15
isinf(x) Returns True if x is a positive or negative infinity and False
otherwise.
num=float(‘inf’) #num is a float number that indicates infinity
print(isinf(num)) gives True
Isnan(x) Returns True if x is a NaN(not a number) and False otherwise
num=float(‘NaN’) #converts NaN into a float representation
print(isnan(num)) gives True
Constants in Math Module
Constant Description
pi The mathematical constant pi value 3.141592
e e= 2.718281
inf A floating point positive infinity. For negative infinity use –
math.inf
nan A floating point not a number (NaN) value
To use these constants and math built functions we should import math module
import math
b=math.sqrt(10)
or
from math import sqrt
b=sqrt(10)
Programs on mathematical functions
Write a python program to calculate area of circle
#python program to find area of a circle
import math
r=4.5
area= math.pi * math.pow (r,2)
print("Area of a circle", math.floor(area))
Output
Area of a circle 63
Thank you

More Related Content

Similar to OPERATORS-PYTHON.pptx ALL OPERATORS ARITHMATIC AND LOGICAL (20)

PYTHON OPERATORS 123Python Operators.pptx
PYTHON OPERATORS 123Python Operators.pptxPYTHON OPERATORS 123Python Operators.pptx
PYTHON OPERATORS 123Python Operators.pptx
AnjaneyuluKunchala1
 
Python operators
Python operatorsPython operators
Python operators
nuripatidar
 
Data Handling
Data Handling Data Handling
Data Handling
bharath916489
 
Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unit
michaelaaron25322
 
python operators.pptx
python operators.pptxpython operators.pptx
python operators.pptx
irsatanoli
 
Python tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online TrainingPython tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online Training
Rahul Tandale
 
Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Programming | JNTUK | UNIT 1 | Lecture 5Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Programming | JNTUK | UNIT 1 | Lecture 5
FabMinds
 
Strings in python are surrounded by eith
Strings in python are surrounded by eithStrings in python are surrounded by eith
Strings in python are surrounded by eith
Orin18
 
python statement, expressions and operators.pptx
python statement, expressions and operators.pptxpython statement, expressions and operators.pptx
python statement, expressions and operators.pptx
richumt
 
Python Operators
Python OperatorsPython Operators
Python Operators
Adheetha O. V
 
operatorsinpython-18112209560412 (1).pptx
operatorsinpython-18112209560412 (1).pptxoperatorsinpython-18112209560412 (1).pptx
operatorsinpython-18112209560412 (1).pptx
urvashipundir04
 
Python notes for students to develop and learn
Python notes for students to develop and learnPython notes for students to develop and learn
Python notes for students to develop and learn
kavithaadhilakshmi
 
Python
PythonPython
Python
Pooriya Kazemzadeh-Heris
 
Operators in python
Operators in pythonOperators in python
Operators in python
deepalishinkar1
 
Python operators
Python operatorsPython operators
Python operators
SaurabhUpadhyay73
 
Python_Module_3_AFkkkkV_Operators-1.pptx
Python_Module_3_AFkkkkV_Operators-1.pptxPython_Module_3_AFkkkkV_Operators-1.pptx
Python_Module_3_AFkkkkV_Operators-1.pptx
tissot723
 
Python assignment 1 Biswajit Mohapatra.pptx
Python assignment 1 Biswajit Mohapatra.pptxPython assignment 1 Biswajit Mohapatra.pptx
Python assignment 1 Biswajit Mohapatra.pptx
BiswajitMohapatra59
 
Operators in python
Operators in pythonOperators in python
Operators in python
Prabhakaran V M
 
Operators_in_Python_Simplified_languages
Operators_in_Python_Simplified_languagesOperators_in_Python_Simplified_languages
Operators_in_Python_Simplified_languages
AbhishekGupta692777
 
PYTHON
PYTHONPYTHON
PYTHON
RidaZaman1
 
PYTHON OPERATORS 123Python Operators.pptx
PYTHON OPERATORS 123Python Operators.pptxPYTHON OPERATORS 123Python Operators.pptx
PYTHON OPERATORS 123Python Operators.pptx
AnjaneyuluKunchala1
 
Python operators
Python operatorsPython operators
Python operators
nuripatidar
 
Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unit
michaelaaron25322
 
python operators.pptx
python operators.pptxpython operators.pptx
python operators.pptx
irsatanoli
 
Python tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online TrainingPython tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online Training
Rahul Tandale
 
Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Programming | JNTUK | UNIT 1 | Lecture 5Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Programming | JNTUK | UNIT 1 | Lecture 5
FabMinds
 
Strings in python are surrounded by eith
Strings in python are surrounded by eithStrings in python are surrounded by eith
Strings in python are surrounded by eith
Orin18
 
python statement, expressions and operators.pptx
python statement, expressions and operators.pptxpython statement, expressions and operators.pptx
python statement, expressions and operators.pptx
richumt
 
operatorsinpython-18112209560412 (1).pptx
operatorsinpython-18112209560412 (1).pptxoperatorsinpython-18112209560412 (1).pptx
operatorsinpython-18112209560412 (1).pptx
urvashipundir04
 
Python notes for students to develop and learn
Python notes for students to develop and learnPython notes for students to develop and learn
Python notes for students to develop and learn
kavithaadhilakshmi
 
Python_Module_3_AFkkkkV_Operators-1.pptx
Python_Module_3_AFkkkkV_Operators-1.pptxPython_Module_3_AFkkkkV_Operators-1.pptx
Python_Module_3_AFkkkkV_Operators-1.pptx
tissot723
 
Python assignment 1 Biswajit Mohapatra.pptx
Python assignment 1 Biswajit Mohapatra.pptxPython assignment 1 Biswajit Mohapatra.pptx
Python assignment 1 Biswajit Mohapatra.pptx
BiswajitMohapatra59
 
Operators_in_Python_Simplified_languages
Operators_in_Python_Simplified_languagesOperators_in_Python_Simplified_languages
Operators_in_Python_Simplified_languages
AbhishekGupta692777
 

More from NagarathnaRajur2 (20)

C-Programming Chapter 1 Fundamentals of C.ppt
C-Programming Chapter 1 Fundamentals of C.pptC-Programming Chapter 1 Fundamentals of C.ppt
C-Programming Chapter 1 Fundamentals of C.ppt
NagarathnaRajur2
 
Basics of C.ppt VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
Basics of C.ppt  VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVBasics of C.ppt  VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
Basics of C.ppt VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
NagarathnaRajur2
 
C-Programming Chapter 1 Fundamentals of C.ppt
C-Programming Chapter 1 Fundamentals of C.pptC-Programming Chapter 1 Fundamentals of C.ppt
C-Programming Chapter 1 Fundamentals of C.ppt
NagarathnaRajur2
 
lecture-ON-C.ppt BASIC WITH DEPTH CONTENT
lecture-ON-C.ppt  BASIC WITH DEPTH CONTENTlecture-ON-C.ppt  BASIC WITH DEPTH CONTENT
lecture-ON-C.ppt BASIC WITH DEPTH CONTENT
NagarathnaRajur2
 
EXCEPTIONS-PYTHON.pptx RUNTIME ERRORS HANDLING
EXCEPTIONS-PYTHON.pptx   RUNTIME ERRORS HANDLINGEXCEPTIONS-PYTHON.pptx   RUNTIME ERRORS HANDLING
EXCEPTIONS-PYTHON.pptx RUNTIME ERRORS HANDLING
NagarathnaRajur2
 
OOPS-PYTHON.pptx OOPS IN PYTHON APPLIED PROGRAMMING
OOPS-PYTHON.pptx    OOPS IN PYTHON APPLIED PROGRAMMINGOOPS-PYTHON.pptx    OOPS IN PYTHON APPLIED PROGRAMMING
OOPS-PYTHON.pptx OOPS IN PYTHON APPLIED PROGRAMMING
NagarathnaRajur2
 
ppt on arm memory.pptx yjjghjghjjjjjjjj
ppt on arm memory.pptx   yjjghjghjjjjjjjjppt on arm memory.pptx   yjjghjghjjjjjjjj
ppt on arm memory.pptx yjjghjghjjjjjjjj
NagarathnaRajur2
 
05_Thumb (15).pptx ARM MICROCONTROLLERS THUMB INSTRUCTIONS WORKING PRINCIPLE
05_Thumb (15).pptx ARM MICROCONTROLLERS THUMB INSTRUCTIONS WORKING PRINCIPLE05_Thumb (15).pptx ARM MICROCONTROLLERS THUMB INSTRUCTIONS WORKING PRINCIPLE
05_Thumb (15).pptx ARM MICROCONTROLLERS THUMB INSTRUCTIONS WORKING PRINCIPLE
NagarathnaRajur2
 
PM.ppt DATA STRUCTURE USING C WITH EXAMPLE PROGRAMES
PM.ppt DATA STRUCTURE USING C    WITH EXAMPLE PROGRAMESPM.ppt DATA STRUCTURE USING C    WITH EXAMPLE PROGRAMES
PM.ppt DATA STRUCTURE USING C WITH EXAMPLE PROGRAMES
NagarathnaRajur2
 
8051 programes -ppt.pptx bnvmmmmmmmmmmmmmmmmmmmmmmmmmmhn
8051 programes -ppt.pptx  bnvmmmmmmmmmmmmmmmmmmmmmmmmmmhn8051 programes -ppt.pptx  bnvmmmmmmmmmmmmmmmmmmmmmmmmmmhn
8051 programes -ppt.pptx bnvmmmmmmmmmmmmmmmmmmmmmmmmmmhn
NagarathnaRajur2
 
Chapter_04_ARM_Assembly.pptx ARM ASSEMBLY CODE
Chapter_04_ARM_Assembly.pptx   ARM ASSEMBLY CODEChapter_04_ARM_Assembly.pptx   ARM ASSEMBLY CODE
Chapter_04_ARM_Assembly.pptx ARM ASSEMBLY CODE
NagarathnaRajur2
 
MEMORY.ppt 8051/8052 MEMORY MANEGEMENT MEMORY DESCRIPTION
MEMORY.ppt 8051/8052  MEMORY MANEGEMENT MEMORY DESCRIPTIONMEMORY.ppt 8051/8052  MEMORY MANEGEMENT MEMORY DESCRIPTION
MEMORY.ppt 8051/8052 MEMORY MANEGEMENT MEMORY DESCRIPTION
NagarathnaRajur2
 
CHAPTER1.pptx ON 8051 MICROCONTROLLER INTRODUCTION CHAPTER
CHAPTER1.pptx  ON 8051 MICROCONTROLLER INTRODUCTION CHAPTERCHAPTER1.pptx  ON 8051 MICROCONTROLLER INTRODUCTION CHAPTER
CHAPTER1.pptx ON 8051 MICROCONTROLLER INTRODUCTION CHAPTER
NagarathnaRajur2
 
Core-Java-by-Mahika-Tutor.9459891.powerpoint.pptx
Core-Java-by-Mahika-Tutor.9459891.powerpoint.pptxCore-Java-by-Mahika-Tutor.9459891.powerpoint.pptx
Core-Java-by-Mahika-Tutor.9459891.powerpoint.pptx
NagarathnaRajur2
 
review.pptx mnbmnbm,nb,n,nm,mn,mn,n,nm,
review.pptx  mnbmnbm,nb,n,nm,mn,mn,n,nm,review.pptx  mnbmnbm,nb,n,nm,mn,mn,n,nm,
review.pptx mnbmnbm,nb,n,nm,mn,mn,n,nm,
NagarathnaRajur2
 
IOT introduction with applications ffffffffffffffffffffff
IOT introduction with applications ffffffffffffffffffffffIOT introduction with applications ffffffffffffffffffffff
IOT introduction with applications ffffffffffffffffffffff
NagarathnaRajur2
 
CORE JAVA PPT FOR ENGINEERS BBBBBBBBBBBBBBBBBBB
CORE JAVA PPT FOR ENGINEERS  BBBBBBBBBBBBBBBBBBBCORE JAVA PPT FOR ENGINEERS  BBBBBBBBBBBBBBBBBBB
CORE JAVA PPT FOR ENGINEERS BBBBBBBBBBBBBBBBBBB
NagarathnaRajur2
 
JAVA CLASS PPT FOR ENGINEERING STUDENTS BBBBBBBBBBBBBBBBBBB
JAVA CLASS PPT FOR ENGINEERING STUDENTS  BBBBBBBBBBBBBBBBBBBJAVA CLASS PPT FOR ENGINEERING STUDENTS  BBBBBBBBBBBBBBBBBBB
JAVA CLASS PPT FOR ENGINEERING STUDENTS BBBBBBBBBBBBBBBBBBB
NagarathnaRajur2
 
JavaSteps. PPT NBNBVNBNVBNNNNNNNNNNNNNN
JavaSteps. PPT  NBNBVNBNVBNNNNNNNNNNNNNNJavaSteps. PPT  NBNBVNBNVBNNNNNNNNNNNNNN
JavaSteps. PPT NBNBVNBNVBNNNNNNNNNNNNNN
NagarathnaRajur2
 
JAVA METHODS PRESENTATION WITH EXAMPLES DFDFFD FDGFDGDFG FGGF
JAVA METHODS PRESENTATION WITH EXAMPLES  DFDFFD   FDGFDGDFG   FGGFJAVA METHODS PRESENTATION WITH EXAMPLES  DFDFFD   FDGFDGDFG   FGGF
JAVA METHODS PRESENTATION WITH EXAMPLES DFDFFD FDGFDGDFG FGGF
NagarathnaRajur2
 
C-Programming Chapter 1 Fundamentals of C.ppt
C-Programming Chapter 1 Fundamentals of C.pptC-Programming Chapter 1 Fundamentals of C.ppt
C-Programming Chapter 1 Fundamentals of C.ppt
NagarathnaRajur2
 
Basics of C.ppt VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
Basics of C.ppt  VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVBasics of C.ppt  VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
Basics of C.ppt VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
NagarathnaRajur2
 
C-Programming Chapter 1 Fundamentals of C.ppt
C-Programming Chapter 1 Fundamentals of C.pptC-Programming Chapter 1 Fundamentals of C.ppt
C-Programming Chapter 1 Fundamentals of C.ppt
NagarathnaRajur2
 
lecture-ON-C.ppt BASIC WITH DEPTH CONTENT
lecture-ON-C.ppt  BASIC WITH DEPTH CONTENTlecture-ON-C.ppt  BASIC WITH DEPTH CONTENT
lecture-ON-C.ppt BASIC WITH DEPTH CONTENT
NagarathnaRajur2
 
EXCEPTIONS-PYTHON.pptx RUNTIME ERRORS HANDLING
EXCEPTIONS-PYTHON.pptx   RUNTIME ERRORS HANDLINGEXCEPTIONS-PYTHON.pptx   RUNTIME ERRORS HANDLING
EXCEPTIONS-PYTHON.pptx RUNTIME ERRORS HANDLING
NagarathnaRajur2
 
OOPS-PYTHON.pptx OOPS IN PYTHON APPLIED PROGRAMMING
OOPS-PYTHON.pptx    OOPS IN PYTHON APPLIED PROGRAMMINGOOPS-PYTHON.pptx    OOPS IN PYTHON APPLIED PROGRAMMING
OOPS-PYTHON.pptx OOPS IN PYTHON APPLIED PROGRAMMING
NagarathnaRajur2
 
ppt on arm memory.pptx yjjghjghjjjjjjjj
ppt on arm memory.pptx   yjjghjghjjjjjjjjppt on arm memory.pptx   yjjghjghjjjjjjjj
ppt on arm memory.pptx yjjghjghjjjjjjjj
NagarathnaRajur2
 
05_Thumb (15).pptx ARM MICROCONTROLLERS THUMB INSTRUCTIONS WORKING PRINCIPLE
05_Thumb (15).pptx ARM MICROCONTROLLERS THUMB INSTRUCTIONS WORKING PRINCIPLE05_Thumb (15).pptx ARM MICROCONTROLLERS THUMB INSTRUCTIONS WORKING PRINCIPLE
05_Thumb (15).pptx ARM MICROCONTROLLERS THUMB INSTRUCTIONS WORKING PRINCIPLE
NagarathnaRajur2
 
PM.ppt DATA STRUCTURE USING C WITH EXAMPLE PROGRAMES
PM.ppt DATA STRUCTURE USING C    WITH EXAMPLE PROGRAMESPM.ppt DATA STRUCTURE USING C    WITH EXAMPLE PROGRAMES
PM.ppt DATA STRUCTURE USING C WITH EXAMPLE PROGRAMES
NagarathnaRajur2
 
8051 programes -ppt.pptx bnvmmmmmmmmmmmmmmmmmmmmmmmmmmhn
8051 programes -ppt.pptx  bnvmmmmmmmmmmmmmmmmmmmmmmmmmmhn8051 programes -ppt.pptx  bnvmmmmmmmmmmmmmmmmmmmmmmmmmmhn
8051 programes -ppt.pptx bnvmmmmmmmmmmmmmmmmmmmmmmmmmmhn
NagarathnaRajur2
 
Chapter_04_ARM_Assembly.pptx ARM ASSEMBLY CODE
Chapter_04_ARM_Assembly.pptx   ARM ASSEMBLY CODEChapter_04_ARM_Assembly.pptx   ARM ASSEMBLY CODE
Chapter_04_ARM_Assembly.pptx ARM ASSEMBLY CODE
NagarathnaRajur2
 
MEMORY.ppt 8051/8052 MEMORY MANEGEMENT MEMORY DESCRIPTION
MEMORY.ppt 8051/8052  MEMORY MANEGEMENT MEMORY DESCRIPTIONMEMORY.ppt 8051/8052  MEMORY MANEGEMENT MEMORY DESCRIPTION
MEMORY.ppt 8051/8052 MEMORY MANEGEMENT MEMORY DESCRIPTION
NagarathnaRajur2
 
CHAPTER1.pptx ON 8051 MICROCONTROLLER INTRODUCTION CHAPTER
CHAPTER1.pptx  ON 8051 MICROCONTROLLER INTRODUCTION CHAPTERCHAPTER1.pptx  ON 8051 MICROCONTROLLER INTRODUCTION CHAPTER
CHAPTER1.pptx ON 8051 MICROCONTROLLER INTRODUCTION CHAPTER
NagarathnaRajur2
 
Core-Java-by-Mahika-Tutor.9459891.powerpoint.pptx
Core-Java-by-Mahika-Tutor.9459891.powerpoint.pptxCore-Java-by-Mahika-Tutor.9459891.powerpoint.pptx
Core-Java-by-Mahika-Tutor.9459891.powerpoint.pptx
NagarathnaRajur2
 
review.pptx mnbmnbm,nb,n,nm,mn,mn,n,nm,
review.pptx  mnbmnbm,nb,n,nm,mn,mn,n,nm,review.pptx  mnbmnbm,nb,n,nm,mn,mn,n,nm,
review.pptx mnbmnbm,nb,n,nm,mn,mn,n,nm,
NagarathnaRajur2
 
IOT introduction with applications ffffffffffffffffffffff
IOT introduction with applications ffffffffffffffffffffffIOT introduction with applications ffffffffffffffffffffff
IOT introduction with applications ffffffffffffffffffffff
NagarathnaRajur2
 
CORE JAVA PPT FOR ENGINEERS BBBBBBBBBBBBBBBBBBB
CORE JAVA PPT FOR ENGINEERS  BBBBBBBBBBBBBBBBBBBCORE JAVA PPT FOR ENGINEERS  BBBBBBBBBBBBBBBBBBB
CORE JAVA PPT FOR ENGINEERS BBBBBBBBBBBBBBBBBBB
NagarathnaRajur2
 
JAVA CLASS PPT FOR ENGINEERING STUDENTS BBBBBBBBBBBBBBBBBBB
JAVA CLASS PPT FOR ENGINEERING STUDENTS  BBBBBBBBBBBBBBBBBBBJAVA CLASS PPT FOR ENGINEERING STUDENTS  BBBBBBBBBBBBBBBBBBB
JAVA CLASS PPT FOR ENGINEERING STUDENTS BBBBBBBBBBBBBBBBBBB
NagarathnaRajur2
 
JavaSteps. PPT NBNBVNBNVBNNNNNNNNNNNNNN
JavaSteps. PPT  NBNBVNBNVBNNNNNNNNNNNNNNJavaSteps. PPT  NBNBVNBNVBNNNNNNNNNNNNNN
JavaSteps. PPT NBNBVNBNVBNNNNNNNNNNNNNN
NagarathnaRajur2
 
JAVA METHODS PRESENTATION WITH EXAMPLES DFDFFD FDGFDGDFG FGGF
JAVA METHODS PRESENTATION WITH EXAMPLES  DFDFFD   FDGFDGDFG   FGGFJAVA METHODS PRESENTATION WITH EXAMPLES  DFDFFD   FDGFDGDFG   FGGF
JAVA METHODS PRESENTATION WITH EXAMPLES DFDFFD FDGFDGDFG FGGF
NagarathnaRajur2
 
Ad

Recently uploaded (20)

"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
Arshad Shaikh
 
LDMMIA About me 2025 Edition 3 College Volume
LDMMIA About me 2025 Edition 3 College VolumeLDMMIA About me 2025 Edition 3 College Volume
LDMMIA About me 2025 Edition 3 College Volume
LDM & Mia eStudios
 
How to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guidesHow to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guides
Celine George
 
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar SirPHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
Diwakar Kashyap
 
STUDENT LOAN TRUST FUND DEFAULTERS GHANA
STUDENT LOAN TRUST FUND DEFAULTERS GHANASTUDENT LOAN TRUST FUND DEFAULTERS GHANA
STUDENT LOAN TRUST FUND DEFAULTERS GHANA
Kweku Zurek
 
Exploring Identity Through Colombian Companies
Exploring Identity Through Colombian CompaniesExploring Identity Through Colombian Companies
Exploring Identity Through Colombian Companies
OlgaLeonorTorresSnch
 
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGYHUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
DHARMENDRA SAHU
 
LDMMIA Free Reiki Yoga S7 Weekly Workshops
LDMMIA Free Reiki Yoga S7 Weekly WorkshopsLDMMIA Free Reiki Yoga S7 Weekly Workshops
LDMMIA Free Reiki Yoga S7 Weekly Workshops
LDM & Mia eStudios
 
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptxQUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
Sourav Kr Podder
 
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATIONTHE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
PROF. PAUL ALLIEU KAMARA
 
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
wygalkelceqg
 
How to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 WebsiteHow to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 Website
Celine George
 
Uterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managmentUterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managment
Ritu480198
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
Dashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo SlidesDashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo Slides
Celine George
 
Multicultural approach in education - B.Ed
Multicultural approach in education - B.EdMulticultural approach in education - B.Ed
Multicultural approach in education - B.Ed
prathimagowda443
 
How to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo SlidesHow to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo Slides
Celine George
 
Diana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda - A Wauconda-Based EducatorDiana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda
 
Critical Thinking and Bias with Jibi Moses
Critical Thinking and Bias with Jibi MosesCritical Thinking and Bias with Jibi Moses
Critical Thinking and Bias with Jibi Moses
Excellence Foundation for South Sudan
 
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
Arshad Shaikh
 
LDMMIA About me 2025 Edition 3 College Volume
LDMMIA About me 2025 Edition 3 College VolumeLDMMIA About me 2025 Edition 3 College Volume
LDMMIA About me 2025 Edition 3 College Volume
LDM & Mia eStudios
 
How to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guidesHow to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guides
Celine George
 
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar SirPHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
Diwakar Kashyap
 
STUDENT LOAN TRUST FUND DEFAULTERS GHANA
STUDENT LOAN TRUST FUND DEFAULTERS GHANASTUDENT LOAN TRUST FUND DEFAULTERS GHANA
STUDENT LOAN TRUST FUND DEFAULTERS GHANA
Kweku Zurek
 
Exploring Identity Through Colombian Companies
Exploring Identity Through Colombian CompaniesExploring Identity Through Colombian Companies
Exploring Identity Through Colombian Companies
OlgaLeonorTorresSnch
 
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGYHUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
DHARMENDRA SAHU
 
LDMMIA Free Reiki Yoga S7 Weekly Workshops
LDMMIA Free Reiki Yoga S7 Weekly WorkshopsLDMMIA Free Reiki Yoga S7 Weekly Workshops
LDMMIA Free Reiki Yoga S7 Weekly Workshops
LDM & Mia eStudios
 
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptxQUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
Sourav Kr Podder
 
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATIONTHE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
PROF. PAUL ALLIEU KAMARA
 
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
wygalkelceqg
 
How to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 WebsiteHow to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 Website
Celine George
 
Uterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managmentUterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managment
Ritu480198
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
Dashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo SlidesDashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo Slides
Celine George
 
Multicultural approach in education - B.Ed
Multicultural approach in education - B.EdMulticultural approach in education - B.Ed
Multicultural approach in education - B.Ed
prathimagowda443
 
How to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo SlidesHow to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo Slides
Celine George
 
Diana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda - A Wauconda-Based EducatorDiana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda
 
Ad

OPERATORS-PYTHON.pptx ALL OPERATORS ARITHMATIC AND LOGICAL

  • 2. Contents Operator Operator precedence and Associativity Mathematical Functions
  • 3. operator An operator is a symbol that performs operation. Operator acts on variables or constants known as operands. If operator acts on single operand then it is called as unary and if acts on two operands then it is called as binary and when acts on three operands it is called as ternary operator. Operators are classified depending upon their nature as..
  • 4. Classification of operators arithmetic assignment unary minus relational  logical  Boolean  bitwise  membership  Identity
  • 5. Arithmetic operator performs basic arithmetic operation like addition, subtraction, multiplication and division. Lets assume a=13 and b=5 operator Meaning Example Result + addition a+b 18 - subtraction a-b 8 * multiplication a*b 65 / division a/b 2.6 % Modulus(remainder) a%b 3 ** Exponent operator a**b 371293 // Integer division a//b 2 TEST1 Writes a python program to perform all arithmetic operations on two variable a=20 and b=6
  • 6. Priority to arithmetic operators 1.parentheses 2.exponent 3.multiplication,division,modulus and floor division are at equal priority 4.Addition and subtraction 5.Assignment Evaluate the following arithmetic expression d=(1+2)*3**2//2+3
  • 7. Assignment Operator stores the right side value to left side variable. Short hand assignments operators used to perform arithmetic operations and stores the result to left side variable. X=20, y=10 and z=5 Operator Example Meaning Result = z=x+y Assignment operator z=30 += z+=x (z=z+x) Shorthand addition assignment operator z=25 -= z-=x (z=z-x) Shorthand subtraction Assignment operator z=-15 *= z*=x z=z*x Shorthand multiplication operator z=100 /= z/=x z=z/x Shorthand division operator Z=0.25 %= z%=x z=z%x Shorthand modulus operator Z=5 **= z**=y z=z**y Shorthand Exponent assignment operator Z=9765625 //= z//=y z=z//y Shorthand division assignment operator 0
  • 8. Contd.. TEST2 Write python program to perform arithmetic operation on x=“20” and y=0xad using shorthand assignment operator Guess the output a=b=1 print(a,b) a=1;b=2 print(a,b) a,b=1,2 print(a,b) Note: python does not support increment(++) and decrement operator
  • 9. Unary Minus Operator The symbol – is used as unary minus operator. This operator is used before a variable, its value is negated. That means if the variable value is positive, it will be converted into negative and vice versa. Example: N=10 print(-N) output: -10 Num=-10 Num=-Num print(Num) output: 10
  • 10. Relational Operators these operators are used for comparison of values. They returns Boolean value True or False. a=1 and b=2 Operator Example Meaning Result > a>b Greater than operator False >= a>=b Greater than or equal to operator False < a<b Less than operator True <= a<=b Less than or equal to True == a==b Equals to operator False != a!=b Not equals operator True
  • 11. Contd.. Relational operators can be chained. It means a single expression can hold more than one relational operators Guess the output x=15 print(10<x<20) print(10>=x<20) print(1<2<3<4) print(1<2>3<4) print(4>2>=2>1)
  • 12. Logical operator Logical operators are used to construct compound condition. A compound condition is a combination of more than one simple condition. Each of the simple condition is evaluated to True or False and then the decision is taken to know whether total condition is True or False. a=10,b=20,c=3,d=5 operator Example Meaning Result and a>b and c>d Logical and False or a>b or c<d Logical or True not not a>b Logical not True
  • 13. Boolean Operators There are three Boolean operators which results True or False. x=True y=False operator Example meaning result and x and y If both are true then it returns true otherwise false False or x or y If either x or y is True then it returns True else False True not not x If x is True it returns False else True. False
  • 14. Guess the output x=10; y=0 print(x and y) # if x and y both evaluated as true then y is returned true # if x is true and y is false then y is returned print(x or y) print(not x) print(not y) OUTPUT 0 10 False True
  • 15. Bitwise operator operates on individual bits ( 0 and 1) of the operands. They can operates on binary number or integers. Complement operator(~) AND operator(&) OR operator(|) XOR operator(^) Left shift operator(<<) Right shift operator(>>)
  • 16. Contd.. Complement of given number is returned by toggling the bits. Example: x=10 X=10=0000 1010 print(~x,bin(~x)) print(~b,bin(~b)) Output -11 ( 1111 0101)
  • 17. AND Operator(&) x=10=0000 1010 y=11=0000 1011 x&y=0000 1010 (10) example x=10; b=15 print(x & b, bin(x &b)) x=0b1001;x=0b1001 print( x & b, bin( x & b) ) Output:
  • 18. Bitwise OR Operator(|) x=10=0000 1010 y=11=0000 1011 X|y=0000 1011 (15) example x=10;b=15 print(x | b, bin(x | b)) x=0b1001;b=0b1001 print( x | b, bin( x | b) ) Output 15 0b1111 9 0b1001
  • 19. Bitwise XOR Operator(^) x=10=0000 1010 y=11=0000 1011 x&y=0000 0001 (15) Example x=10 b=15 print(x ^ b, bin(x ^b)) x=0b1001 b=0b1001 print( x ^ b, bin( x ^b) ) Output 5 0b101 0 0b0
  • 20. Bitwise left shift operator(<<): shifts the bits of the number towards left specified number of positions. x=10 X<<2 0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 ( first time shift) 0 0 1 0 1 0 0 0 ( second time shift) (40) Example x=10 print(x<<2, bin(x<<2)) x=0b1001 print(x<<1,bin(x<<1)) Output 40 0b101000
  • 21. Bitwise right shift operator(>>): shifts the bits of the number towards right specified number of positions. x=10 X>>2 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 1 ( first time shift) 0 0 0 0 0 0 1 0 ( second time shift) (2) Example x=10 print(x>>2, bin(x>>2)) x=0b1001 print(x>>1,bin(x>>1)) Output 2 0b10 4 0b100
  • 22. Membership operators: to test a member is in sequence such as list, string, tuple and dictionary in operator: it returns True if an element is found in specified sequence otherwise returns False. Example: City=[‘Belagum’, ‘Bombay’, ’Mysore’ , ‘Lucknow’] for k in City: print(k) If ‘Mysore’ in City: print(“yes”) else: print(“no”) Output Belagum Bombay Mysore Lucknow yes
  • 23. Contd.. not in operator: Works in reverse manner for in operator. This operator returns True if an element is not found in the sequence City=["Belagum" , "Bombay" , "Mysore" , "Lucknow"] if "Mysore" not in City: print("yes") else: print("no") Output: no
  • 24. Identity Operator The memory location of object can be seen using the id() function. This function returns an integer number called the identity number that internally represents the memory location of the object. a=25 b=25 print(id(a),id(b)) b=47 print(id(a),id(b)) Output 140731879209504 140731879209504 140731879209504 140731879210208
  • 25. The is operator is operator compare whether two objects identity numbers are same or not. If same it returns True otherwise False. a=25 b=25 if a is b: print("Both have same identity") else: print("They do not have same identity") Output Both have same identity
  • 26. is not operator If the identity numbers of two objects being compared are not same then it returns True otherwise False. a=25 b=35 if a is not b: print("They do not have same identity") else: print("Both have same identity") Output They do not have same identity
  • 27. Operator precedence and associativity operator Name () Parenthesis ** Exponentiation -,~ Unary minus, bitwise complement *, /,//,% Multiplication, division, floor division, modulus +,- Addition, subtraction <<,>> Bitwise left shift, bitwise right shift & Bitwise AND ^ Bitwise XOR | Bitwise OR >,>=,<,<=,==,!= Relational operators
  • 28. Contd.. Operator Meaning =, %=,/=,//=,-=,+=,*=,**= Assignment operators Is, is not Identity operators In, not in Membership operator not Logical not or Logical or and Logical Associativity: In an expression if we have more than one operators with same priority then we have to flow the associativity of a operator. Associativity operator is either from left to right or right to left. All operators have the associativity from left to right except assignment operator.
  • 29. Expression evaluation Value=3/2*4+3+(10/4)**3-2 Ans: 22.625 ValueAns:12 Value = 23<45 and 67-89>-10 Ans: False Value=15<<3 + 65//6-7**2 or 8%2 Ans: ValueError: negative shift count Value=not 78/4+(5-2) Ans:False
  • 30. Mathematical Functions Functions Description ceil(x) Raises x value to the next higher integer. If x is integer then same value is returned ceil(4.5) gives 5 floor(x) Decreases x value to the previous integer value. If x is integer then the same value is returned. floor(4.5) gives 4 degree(x) Converts angle value x from radians into degrees degree(3.142) gives 179.999 radians(x) Converts x value from degrees into radians radians(180) gives 3.142 sin(x) Gives sine value of x. Here x value is given in radians. sin(0.5) gives 0.4794 cos(x) Gives cosine value of x. Here x value is given in radians. cos(0.5) gives 0.87758 tan(x) Gives tangent value of x. Here x value is given in radians. tan(0.5) gives 0.5463 exp(x) returns exponentiation of x. This is same as e **x exp(0.5) returns 1.64872
  • 31. Function Description fabs(x) Gives the absolute value of x fabs(-4.56) gives 4.56 factorial(x) Returns factorial value of x. Raises value error if x is not integer or is negative factorial(4) gives 24 fmod(x,y) Returns remainder of division of x and y. fmod() is preferred to calculate modulus for float values than % operator. It works well for integer values. fmod(14.5,3) gives 2.5 fsum(values) Returns accurate sum of floating point values fsum([1.5,2.4,-3.3]) returns 0.6000 modf(x) Returns float and integral part of x modf(2.56) gives(0.56,2.0) Log10(x) Returns logarithm of x for base 10 Log10(5.2345) gives 0.71888 Log(x,[base]) Returns the natural logarithm of x of specified base log(5.5,2) gives 2.45943 Sqrt(x) Returns positive square root value of x Sqrt(49) gives 7
  • 32. Function Description pow(x,y) Raises x value to the power of y pow(5,3) returns 125.0 gcd(x,y) Gives greatest common divisor of x and y. Available from python 3.5 onwards gcd(25,30) gives 5 trunc(x) The real value of x is truncated to integer value and returned trunc(15.5676) gives 15 isinf(x) Returns True if x is a positive or negative infinity and False otherwise. num=float(‘inf’) #num is a float number that indicates infinity print(isinf(num)) gives True Isnan(x) Returns True if x is a NaN(not a number) and False otherwise num=float(‘NaN’) #converts NaN into a float representation print(isnan(num)) gives True
  • 33. Constants in Math Module Constant Description pi The mathematical constant pi value 3.141592 e e= 2.718281 inf A floating point positive infinity. For negative infinity use – math.inf nan A floating point not a number (NaN) value To use these constants and math built functions we should import math module import math b=math.sqrt(10) or from math import sqrt b=sqrt(10)
  • 34. Programs on mathematical functions Write a python program to calculate area of circle #python program to find area of a circle import math r=4.5 area= math.pi * math.pow (r,2) print("Area of a circle", math.floor(area)) Output Area of a circle 63