SlideShare a Scribd company logo
M Vishnuvardhan
Operators
Operators are used to perform operations on variables and values
» Arithmetic operators
» Assignment operators
» Comparison operators
» Logical operators
» Identity operators
» Membership operators
» Bitwise operators
M Vishnuvardhan
Arithmetic Operators
Operator Name Example
+ Addition x + y
- Subtraction x - y
* Multiplication x * y
/ Division x / y
% Modulus x % y
** Exponentiation x ** y
// Floor division x // y
M Vishnuvardhan
Comparison Operators
» Comparison operators are used to form conditions which always returns Boolean
values either True or False.
Operator Name Example
== Equal x == y
!= Not equal x != y
> Greater than x > y
< Less than x < y
>=
Greater than or
equal to
x >= y
<= Less than or equal to x <= y
M Vishnuvardhan
Logical Operators
» Logical operators are used to combine conditional statements:
Operator Description Example
and
Returns True if both statements are
true
x < 5 and x < 10
or
Returns True if one of the statements is
true
x < 5 or x < 4
not
Reverse the result, returns False if the
result is true
not(x < 5 and x <
10)
M Vishnuvardhan
Identity Operators
» Identity operators are used to compare the objects, not if they are equal, but if
they are actually the same object, with the same memory location:
Operator Description Example
is
Returns True if both variables are the
same object
x is y
is not
Returns True if both variables are not the
same object
x is not y
M Vishnuvardhan
Membership Operators
» Membership operators are used to test if a sequence is presented in an object
Operator Description Example
in Returns True if a sequence with the specified
value is present in the object
x in y
not in Returns True if a sequence with the specified
value is not present in the object
x not in y
M Vishnuvardhan
Bitwise Operators
Bitwise operators are used to compare (binary) numbers
Operator Name Description
& AND Sets each bit to 1 if both bits are 1
| OR Sets each bit to 1 if one of two bits is 1
^ XOR Sets each bit to 1 if only one of two bits is 1
~ NOT Inverts all the bits
<< Zero fill left
shift
Shift left by pushing zeros in from the right and let
the leftmost bits fall off
>> Signed right
shift
Shift right by pushing copies of the leftmost bit in
from the left, and let the rightmost bits fall off
M Vishnuvardhan
Bitwise Logical Operators
Bitwise logical operators are evaluated as follows
A B A & B A | B A^B
1 1 1 1 0
1 0 0 1 1
0 1 0 1 1
0 0 0 0 0
M Vishnuvardhan
Bitwise Shift Operators
» The << left shift operators shifts the number to left wards by specified number of
bits. The result of the number is multiplied by the 2 raised to number of places
shifted
i.e, a<<n  a=a*2n
Eg: a =8 a<< 1  a=a*2  16
» The >> right shift operators shifts the number to right wards by specified number
of bits. The result of the number is multiplied by the 2 raised to number of places
shifted
i.e, a<<n  a=a / 2n
Eg: a =8 a>> 3  a=a / 23  1
M Vishnuvardhan
Assignment Statement
» Basic form: Eg: student = 'SSBN’
» Tuple assignment: Eg: x, y = 50, 100 # equivalent to: (x, y) = (50, 100)
» List assignment: Eg: [x, y] = [50, 100] # equivalent to: (x, y) = (50, 100)
» Sequence assignment: Eg: a, b, c, d= ‘SSBN’
» Extended Sequence unpacking: Eg: p, *q = 'Hello’
ranks = ['A', 'B', 'C', 'D’]
first, *rest = ranks
» Multiple- target assignment: Eg: x = y = 75
» Augmented assignment: Eg: x = 2
x += 1 # equivalent to: x = x + 1
M Vishnuvardhan
Print Statement
The Print statement actually is Python function used to output data to the
standard output device (screen). Print () can also be used to output data to a file.
Syntax: print(*objects, sep=' ', end='n', file=sys.stdout, flush=False)
The sep separator is used between the values. It defaults into a space character.
After all values are printed, end is printed. It defaults into a new line.
The file is the object where the values are printed and its default value is
sys.stdout (screen).
M Vishnuvardhan
Print Statement
Eg: print('This sentence is output to the screen’)
# prints This sentence is output to the screen
a = 5
print('The value of a is', a) # prints The value of a is 5
print(1,2,3,4) # prints: 1 2 3 4
print(1,2,3,4,sep='*') #prints : 1*2*3*4
print(1,2,3,4,sep='#',end='&') #prints: 1#2#3#4&
M Vishnuvardhan
Output formatting
To format the output so as to make it look attractive, str. format () method is used.
Eg: x = 5; y = 10
print('The value of x is {} and y is {}'.format(x,y)) #The value of x is 5 and y is 10
Here the curly braces {} are used as placeholders and the variables are printed in
the place holders as they appear in format().
Eg:
print('I love {0} and {1}'.format('bread','butter')) #prints: I love bread and butter
print('I love {1} and {0}'.format('bread','butter')) #prints: I love butter and bread
M Vishnuvardhan
Output formatting
» It possible to use keyword arguments to format the string.
Eg:
print('Hello {name}, {greeting}'.format(greeting = 'Goodmorning', name = 'John'))
# prints Hello John, Goodmorning
» It possible to format strings like the old printf() style used in C language. The %
(format specifier) is used to accomplish this.
Eg: x = 12.3456789
print('The value of x is %3.2f' %x) # prints The value of x is 12.35
print('The value of x is %3.4f' %x) # prints The value of x is 12.3457
M Vishnuvardhan
input statement
The input() function takes the input from the user. Type of the returned object
always will be <type ‘str’>
Syntax input(prompt)
Here prompt A String, representing a default message before the input
Eg: num = input('Enter a number: ')
Here the entered value 10 is a string, not a number. To convert this into a number
use int() or float() functions. This same operation can be performed using the eval()
function.
M Vishnuvardhan
import statement
The import keyword is used to import modules.
import moduleName
Eg: import dateTime
x = datetime.datetime.now()
import module as aliasName
Eg: import dateTime as D
x=D.datetime.now()
M Vishnuvardhan

More Related Content

Similar to Python Operators.pptx

Operators in Python
Operators in PythonOperators in Python
Operators in Python
Anusuya123
 
Operators
OperatorsOperators
Regression
RegressionRegression
Regression
ramyaranjith
 
Data Handling.pdf
Data Handling.pdfData Handling.pdf
Data Handling.pdf
MILANOP1
 
Introduction to C programming language. Coding
Introduction to C programming language. CodingIntroduction to C programming language. Coding
Introduction to C programming language. Coding
TanishqGosavi
 
Data Handling
Data Handling Data Handling
Data Handling
bharath916489
 
1. control structures in the python.pptx
1. control structures in the python.pptx1. control structures in the python.pptx
1. control structures in the python.pptx
DURAIMURUGANM2
 
Python unit 3 and Unit 4
Python unit 3 and Unit 4Python unit 3 and Unit 4
Python unit 3 and Unit 4
Anandh Arumugakan
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
Sowmya Jyothi
 
This slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptxThis slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptx
ranaashutosh531pvt
 
C programming Tutorial Session 3
C programming Tutorial Session 3C programming Tutorial Session 3
C programming Tutorial Session 3
Muhammad Ehtisham Siddiqui
 
C programming Tutorial Session 4
C programming Tutorial Session 4C programming Tutorial Session 4
C programming Tutorial Session 4
Muhammad Ehtisham Siddiqui
 
Python Operators
Python OperatorsPython Operators
Python Operators
Adheetha O. V
 
Python operator, data types.pptx
Python operator, data types.pptxPython operator, data types.pptx
Python operator, data types.pptx
BhumaNagaPavan
 
Data Analysis and Programming in R
Data Analysis and Programming in RData Analysis and Programming in R
Data Analysis and Programming in REshwar Sai
 
Machine learning
Machine learningMachine learning
Machine learning
Shreyas G S
 
Types of Operators in C programming .pdf
Types of Operators in C programming  .pdfTypes of Operators in C programming  .pdf
Types of Operators in C programming .pdf
RichardMathengeSPASP
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
BAINIDA
 
SPL 6 | Operators in C
SPL 6 | Operators in CSPL 6 | Operators in C
SPL 6 | Operators in C
Mohammad Imam Hossain
 

Similar to Python Operators.pptx (20)

Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
Operators
OperatorsOperators
Operators
 
Regression
RegressionRegression
Regression
 
Data Handling.pdf
Data Handling.pdfData Handling.pdf
Data Handling.pdf
 
Introduction to C programming language. Coding
Introduction to C programming language. CodingIntroduction to C programming language. Coding
Introduction to C programming language. Coding
 
Data Handling
Data Handling Data Handling
Data Handling
 
1. control structures in the python.pptx
1. control structures in the python.pptx1. control structures in the python.pptx
1. control structures in the python.pptx
 
Python unit 3 and Unit 4
Python unit 3 and Unit 4Python unit 3 and Unit 4
Python unit 3 and Unit 4
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
 
This slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptxThis slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptx
 
C programming Tutorial Session 3
C programming Tutorial Session 3C programming Tutorial Session 3
C programming Tutorial Session 3
 
C programming Tutorial Session 4
C programming Tutorial Session 4C programming Tutorial Session 4
C programming Tutorial Session 4
 
Python Operators
Python OperatorsPython Operators
Python Operators
 
Python operator, data types.pptx
Python operator, data types.pptxPython operator, data types.pptx
Python operator, data types.pptx
 
Data Analysis and Programming in R
Data Analysis and Programming in RData Analysis and Programming in R
Data Analysis and Programming in R
 
Machine learning
Machine learningMachine learning
Machine learning
 
Types of Operators in C programming .pdf
Types of Operators in C programming  .pdfTypes of Operators in C programming  .pdf
Types of Operators in C programming .pdf
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
 
SPL 6 | Operators in C
SPL 6 | Operators in CSPL 6 | Operators in C
SPL 6 | Operators in C
 
Java - Operators
Java - OperatorsJava - Operators
Java - Operators
 

More from M Vishnuvardhan Reddy

Python Sets_Dictionary.pptx
Python Sets_Dictionary.pptxPython Sets_Dictionary.pptx
Python Sets_Dictionary.pptx
M Vishnuvardhan Reddy
 
Lists_tuples.pptx
Lists_tuples.pptxLists_tuples.pptx
Lists_tuples.pptx
M Vishnuvardhan Reddy
 
Python Control Structures.pptx
Python Control Structures.pptxPython Control Structures.pptx
Python Control Structures.pptx
M Vishnuvardhan Reddy
 
Python Strings.pptx
Python Strings.pptxPython Strings.pptx
Python Strings.pptx
M Vishnuvardhan Reddy
 
Python Basics.pptx
Python Basics.pptxPython Basics.pptx
Python Basics.pptx
M Vishnuvardhan Reddy
 
Python Datatypes.pptx
Python Datatypes.pptxPython Datatypes.pptx
Python Datatypes.pptx
M Vishnuvardhan Reddy
 
DataScience.pptx
DataScience.pptxDataScience.pptx
DataScience.pptx
M Vishnuvardhan Reddy
 
Html forms
Html formsHtml forms
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
M Vishnuvardhan Reddy
 
Java Threads
Java ThreadsJava Threads
Java Threads
M Vishnuvardhan Reddy
 
Java Streams
Java StreamsJava Streams
Java Streams
M Vishnuvardhan Reddy
 
Scanner class
Scanner classScanner class
Scanner class
M Vishnuvardhan Reddy
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
M Vishnuvardhan Reddy
 
Java intro
Java introJava intro
Java applets
Java appletsJava applets
Java applets
M Vishnuvardhan Reddy
 
Exception handling
Exception handling Exception handling
Exception handling
M Vishnuvardhan Reddy
 
Control structures
Control structuresControl structures
Control structures
M Vishnuvardhan Reddy
 
Constructors
ConstructorsConstructors
Constructors
M Vishnuvardhan Reddy
 
Classes&amp;objects
Classes&amp;objectsClasses&amp;objects
Classes&amp;objects
M Vishnuvardhan Reddy
 
Shell sort
Shell sortShell sort

More from M Vishnuvardhan Reddy (20)

Python Sets_Dictionary.pptx
Python Sets_Dictionary.pptxPython Sets_Dictionary.pptx
Python Sets_Dictionary.pptx
 
Lists_tuples.pptx
Lists_tuples.pptxLists_tuples.pptx
Lists_tuples.pptx
 
Python Control Structures.pptx
Python Control Structures.pptxPython Control Structures.pptx
Python Control Structures.pptx
 
Python Strings.pptx
Python Strings.pptxPython Strings.pptx
Python Strings.pptx
 
Python Basics.pptx
Python Basics.pptxPython Basics.pptx
Python Basics.pptx
 
Python Datatypes.pptx
Python Datatypes.pptxPython Datatypes.pptx
Python Datatypes.pptx
 
DataScience.pptx
DataScience.pptxDataScience.pptx
DataScience.pptx
 
Html forms
Html formsHtml forms
Html forms
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
 
Java Threads
Java ThreadsJava Threads
Java Threads
 
Java Streams
Java StreamsJava Streams
Java Streams
 
Scanner class
Scanner classScanner class
Scanner class
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Java intro
Java introJava intro
Java intro
 
Java applets
Java appletsJava applets
Java applets
 
Exception handling
Exception handling Exception handling
Exception handling
 
Control structures
Control structuresControl structures
Control structures
 
Constructors
ConstructorsConstructors
Constructors
 
Classes&amp;objects
Classes&amp;objectsClasses&amp;objects
Classes&amp;objects
 
Shell sort
Shell sortShell sort
Shell sort
 

Recently uploaded

PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Zilliz
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 

Recently uploaded (20)

PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 

Python Operators.pptx

  • 1.
  • 2. M Vishnuvardhan Operators Operators are used to perform operations on variables and values » Arithmetic operators » Assignment operators » Comparison operators » Logical operators » Identity operators » Membership operators » Bitwise operators
  • 3. M Vishnuvardhan Arithmetic Operators Operator Name Example + Addition x + y - Subtraction x - y * Multiplication x * y / Division x / y % Modulus x % y ** Exponentiation x ** y // Floor division x // y
  • 4. M Vishnuvardhan Comparison Operators » Comparison operators are used to form conditions which always returns Boolean values either True or False. Operator Name Example == Equal x == y != Not equal x != y > Greater than x > y < Less than x < y >= Greater than or equal to x >= y <= Less than or equal to x <= y
  • 5. M Vishnuvardhan Logical Operators » Logical operators are used to combine conditional statements: Operator Description Example and Returns True if both statements are true x < 5 and x < 10 or Returns True if one of the statements is true x < 5 or x < 4 not Reverse the result, returns False if the result is true not(x < 5 and x < 10)
  • 6. M Vishnuvardhan Identity Operators » Identity operators are used to compare the objects, not if they are equal, but if they are actually the same object, with the same memory location: Operator Description Example is Returns True if both variables are the same object x is y is not Returns True if both variables are not the same object x is not y
  • 7. M Vishnuvardhan Membership Operators » Membership operators are used to test if a sequence is presented in an object Operator Description Example in Returns True if a sequence with the specified value is present in the object x in y not in Returns True if a sequence with the specified value is not present in the object x not in y
  • 8. M Vishnuvardhan Bitwise Operators Bitwise operators are used to compare (binary) numbers Operator Name Description & AND Sets each bit to 1 if both bits are 1 | OR Sets each bit to 1 if one of two bits is 1 ^ XOR Sets each bit to 1 if only one of two bits is 1 ~ NOT Inverts all the bits << Zero fill left shift Shift left by pushing zeros in from the right and let the leftmost bits fall off >> Signed right shift Shift right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off
  • 9. M Vishnuvardhan Bitwise Logical Operators Bitwise logical operators are evaluated as follows A B A & B A | B A^B 1 1 1 1 0 1 0 0 1 1 0 1 0 1 1 0 0 0 0 0
  • 10. M Vishnuvardhan Bitwise Shift Operators » The << left shift operators shifts the number to left wards by specified number of bits. The result of the number is multiplied by the 2 raised to number of places shifted i.e, a<<n  a=a*2n Eg: a =8 a<< 1  a=a*2  16 » The >> right shift operators shifts the number to right wards by specified number of bits. The result of the number is multiplied by the 2 raised to number of places shifted i.e, a<<n  a=a / 2n Eg: a =8 a>> 3  a=a / 23  1
  • 11. M Vishnuvardhan Assignment Statement » Basic form: Eg: student = 'SSBN’ » Tuple assignment: Eg: x, y = 50, 100 # equivalent to: (x, y) = (50, 100) » List assignment: Eg: [x, y] = [50, 100] # equivalent to: (x, y) = (50, 100) » Sequence assignment: Eg: a, b, c, d= ‘SSBN’ » Extended Sequence unpacking: Eg: p, *q = 'Hello’ ranks = ['A', 'B', 'C', 'D’] first, *rest = ranks » Multiple- target assignment: Eg: x = y = 75 » Augmented assignment: Eg: x = 2 x += 1 # equivalent to: x = x + 1
  • 12. M Vishnuvardhan Print Statement The Print statement actually is Python function used to output data to the standard output device (screen). Print () can also be used to output data to a file. Syntax: print(*objects, sep=' ', end='n', file=sys.stdout, flush=False) The sep separator is used between the values. It defaults into a space character. After all values are printed, end is printed. It defaults into a new line. The file is the object where the values are printed and its default value is sys.stdout (screen).
  • 13. M Vishnuvardhan Print Statement Eg: print('This sentence is output to the screen’) # prints This sentence is output to the screen a = 5 print('The value of a is', a) # prints The value of a is 5 print(1,2,3,4) # prints: 1 2 3 4 print(1,2,3,4,sep='*') #prints : 1*2*3*4 print(1,2,3,4,sep='#',end='&') #prints: 1#2#3#4&
  • 14. M Vishnuvardhan Output formatting To format the output so as to make it look attractive, str. format () method is used. Eg: x = 5; y = 10 print('The value of x is {} and y is {}'.format(x,y)) #The value of x is 5 and y is 10 Here the curly braces {} are used as placeholders and the variables are printed in the place holders as they appear in format(). Eg: print('I love {0} and {1}'.format('bread','butter')) #prints: I love bread and butter print('I love {1} and {0}'.format('bread','butter')) #prints: I love butter and bread
  • 15. M Vishnuvardhan Output formatting » It possible to use keyword arguments to format the string. Eg: print('Hello {name}, {greeting}'.format(greeting = 'Goodmorning', name = 'John')) # prints Hello John, Goodmorning » It possible to format strings like the old printf() style used in C language. The % (format specifier) is used to accomplish this. Eg: x = 12.3456789 print('The value of x is %3.2f' %x) # prints The value of x is 12.35 print('The value of x is %3.4f' %x) # prints The value of x is 12.3457
  • 16. M Vishnuvardhan input statement The input() function takes the input from the user. Type of the returned object always will be <type ‘str’> Syntax input(prompt) Here prompt A String, representing a default message before the input Eg: num = input('Enter a number: ') Here the entered value 10 is a string, not a number. To convert this into a number use int() or float() functions. This same operation can be performed using the eval() function.
  • 17. M Vishnuvardhan import statement The import keyword is used to import modules. import moduleName Eg: import dateTime x = datetime.datetime.now() import module as aliasName Eg: import dateTime as D x=D.datetime.now()