SlideShare a Scribd company logo
Python basics
 Introduction-
 What is Python?
 Python History
 Features of Python
 Applications of Python
 Architecture and Working of Python
 Python Constructs
 Python vs Java vs C++
 Python is a General Purpose object-oriented
programming language, which means that it
can model real-world entities. It is also
dynamically-typed because it carries out
type-checking at runtime.
 Python is an interpreted language.
 Guido van Rossum named it after the comedy
group Monty Python
 Python was developed in the late 1980s and was
named after the BBC TV show Monty Python’s
Flying Circus.
 Guido van Rossum started implementing Python
at CWI in the Netherlands in December of 1989.
 This was a successor to the ABC programming
language which was capable of exception
handling and interfacing with the Amoeba
operating system.
 On October 16 of 2000, Python 2.0 released with
many new features.
 Then Python 3.0 released on December 3, 2008
 Python is the “most powerful language you
can still read”, Says Paul Dubois
 Python is one of the richest Programming
languages.
 Going by the TIOBE Index, it is the Second
Most Popular Programming Language in the
world.
 Easy
When writing code in Python, you need fewer
lines of code compared to languages like
Java.
 Interpreted
It is interpreted(executed) line by line. This
makes it easy to test and debug.
 Object-Oriented
The Python programming language supports
classes and objects and hence it is object-
oriented.
 Free and Open Source
The language and its source code are available to the
public for free; there is no need to buy a costly license.
 Portable
Since Python is open-source, you can run it on Windows,
Mac, Linux or any other platform. Your programs will work
without any need to change it for every machine.
 GUI Programming
You can use it to develop a GUI (Graphical User Interface).
One way to do this is through Tkinter.
 Large Python Library
Python provides you with a large standard library.
You can use it to implement a variety of functions without
the need to reinvent the wheel every time. Just pick the
code you need and continue
 Build a website using Python
 Develop a game in Python
 Perform Computer Vision (Facilities like face-
detection and color-detection)
 Implement Machine Learning (Give a computer
the ability to learn)
 Enable Robotics with Python
 Perform Web Scraping (Harvest data from
websites)
 Perform Data Analysis using Python
 Automate a web browser
 Perform Scripting in Python
 Build Artificial Intelligence
 Parser
It uses the source code to generate an
abstract syntax tree.
 Compiler
It turns the abstract syntax tree into Python
bytecode.
 Interpreter
It executes the code line by line in a REPL
(Read-Evaluate-Print-Loop) fashion.
 Functions in Python
 Classes in Python
 Module Packages in Python
 Packages in Python
 List in Python
 Tuple in Python
 Dictionary in Python
 Comments and Docstrings in Python(#, ’’ ’’ “)
 How does Python get its name?
 What are the Features of Python that make it
so popular?
 Define Modules in Python?
 What is the difference between List and Tuple
in Python?
 Compare Python with Java
 A variable is a container for a value. It can be
assigned a name, you can use it to refer to it
later in the program.
 Based on the value assigned, the interpreter
decides its data type.
 x=45 type =integer
 Name=“seed” type = string
 List1=[1,22,33] type = list
 A variable can have a short name (like x and
y) or a more descriptive name (age, carname,
total_volume).
 Rules for Python variables:
1. A variable name must start with a letter or the
underscore character
2. A variable name cannot start with a number
3. A variable name can only contain alpha-numeric
characters and underscores (A-z, 0-9, and _ )
4. Variable names are case-sensitive (age, Age and
AGE are three different variables)
Valid Variable Names Invalid Variable Names
 myval = “Krushna"
my_val = “krushna"
_my_val = “krushna"
myVal = ’krushna’
MYVAL = “krushna"
myval2 = “Krushna“
 Roll_no =23
 rollno1 = 45
 Inavlid Variable Names:
 2myval = “hello"
my-var = “hello"
my var = “hello“
 roll&no = 45
 assign a value to Python variables, you don’t
need to declare its type
 type the value after the equal sign(=).
 You cannot use Python variables before
assigning it a value.
 You can’t put the identifier on the right-hand
side of the equal sign, though. The following
code causes an error.
 You can’t assign Python variables to a
keyword.
 You can assign values to multiple Python variables in one
statement.
1. pin, city=11,‘Pune'
print(pin , city)
2. a,b,c = 11,22,33
print(a)
print(b)
print(c)
 you can assign the same value to multiple Python
variables.
 a=b=7
print(a,b)
 You can also delete Python variables using
the keyword ‘del’.
a='red'
del a
 Python has five standard data types −
Numbers
String
List
Tuple
Dictionary
 Number data types store numeric values.
Number objects are created when you assign
a value to them.
For example −
var1 = 1 var2 = 70
 Python supports four different numerical
types −
1. int (signed integers)
2. float (floating point real values)
3. complex (complex numbers)
x = 11 # int
y = 2.85 # float
z = 4+1j # complex
Float can also be scientific numbers with an
"e" to indicate the power of 10.
x = 35e3 # float
y = 12E4 # float
z = -87.7e100 #float
You can convert from one type to another with the int(), float(),
and complex() methods:
x = 1 # int
y = 2.8 # float
z = 1j # complex
#convert from int to float:
a = float(x)
#convert from float to int:
b = int(y)
#convert from int to complex:
c = complex(x)
 Note: You cannot convert complex numbers into another
number type.
x = str("s1") # x will be 's1‘
y = str(2) # y will be '2‘
z = str(3.0) # z will be '3.0'
 isinstance() function to tell if Python
variables belong to a particular class. It takes
two parameters- the variable/value, and the
class.
 >>> print(isinstance(a,complex))
 2. Strings
A string is a sequence of characters. Python
does not have a char data type, unlike C++
or Java. You can delimit a string using single
quotes or double-quotes.
 >>> city='Ahmednagar'
 >>> city
 What do you mean by scope?
 What are the types of variable scope?
 What is scope of variable with example?
 What are python variables?
 How do you declare a variable in Python 3?
Operator Name Example
+ Addition a+b
- Subtraction a-y
* Multiplication a*y
/ Division a / b
% Modulus a % b
** Exponentiation a ** b
// Floor division a //b
Operator Example Same As
= x = 5 x = 5
+= x += 3 x = x + 3
-= x -= 3 x = x - 3
*= x *= 3 x = x * 3
/= x /= 3 x = x / 3
%= x %= 3 x = x % 3
//= x //= 3 x = x // 3
**= x **= 3 x = x ** 3
|= x |= 3 x = x | 3
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
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)
 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
 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
 Bitwise operators are used to compare
(binary) numbers:

Operator Name Description
& Binary AND Sets each bit to 1 if both bits are 1
| Binary OR Sets each bit to 1 if one of two bits is 1
^ Binary XOR Sets each bit to 1 if only one of two bits is
1
~ Binary 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
1. 5 & 2 => 0101 & 0010 =>0000
2. 5 | 2 => 0101 & 0010 =>0101
3. 5 ^ 3 => 0101 & 0011 =>0110
4. ~5 => ~ 0101 => 1010
5. 10<<1 => 1010<<1 => 10100
6. 10>>1 => 1010 >>1 => 00101
 Strings in Python are identified as a contiguous
set of characters represented in the quotation
marks.
 strings in Python are arrays of bytes representing
unicode characters.
 Python allows for either pairs of single or double
quotes
print("Hello")
print(‘Hello’)
 Assign String to a Variable
a = "Hello"
print(a)
 You can assign a multiline string to a variable
by using three single or double quotes:
 Example
◦ Name = “ ” ” Hello,I am an Interpreter “ “ “
◦ print(Name)
◦ Name = ‘ ‘ ‘ Hello,I am an Interpreter ’ ’ ’
◦ print(Name)
 str = 'Hello World!'
 print (str) # Prints complete string
 print str * 2 # Prints string two times
 print str + "TEST" # Prints concatenated string
 You can return a range of characters by using the slice
 Specify the start index and the end index, separated by a
colon, to return a part of the string.
To display only a part of a string ,use the slicing operator
[].
 print(str[0]) # Prints first character of the string at 0th
index or position
 print str[2:5] # Prints characters starting from 2nd to 4th
character
 print str[2:] # Prints string starting from 2nd character
 Note: The first character has index 0.
 print(b[:5]) # print the characters from the
start to position 5 (not included)
 print(b[2:]) # print the characters from
position 2, and to the end
 Use negative indexes to start the slice from the end of the
string
 print(b[-5:-2]) #
H E L L O 7
[0] [1] [2] [3] [4] [5] Positive
index
[-6] [-5] [-4] [-3] [-2] [-1] Negative
index
 Python Strings can join using the
concatenation operator +.
 a='Do you see this, '
 b='$$?'
a+b
 a='10'
print(2*a)

More Related Content

What's hot (19)

PPT
Introduction to Python - Part Two
amiable_indian
 
PPTX
Python ppt
Anush verma
 
PPTX
Python second ppt
RaginiJain21
 
PPTX
An Introduction : Python
Raghu Kumar
 
PDF
Python Basics
tusharpanda88
 
PPTX
Introduction to the basics of Python programming (part 1)
Pedro Rodrigues
 
PPT
Introduction to Python - Part Three
amiable_indian
 
PPTX
Chapter 9 python fundamentals
Praveen M Jigajinni
 
PPTX
Fundamentals of Python Programming
Kamal Acharya
 
PPTX
Python programming
Ashwin Kumar Ramasamy
 
PPTX
Python Basics
Adheetha O. V
 
PPTX
Python-04| Fundamental data types vs immutability
Mohd Sajjad
 
PDF
Introduction To Programming with Python
Sushant Mane
 
PDF
Python for data science by www.dmdiploma.com
ShwetaAggarwal56
 
PPTX
Learn Python The Hard Way Presentation
Amira ElSharkawy
 
PDF
Let’s Learn Python An introduction to Python
Jaganadh Gopinadhan
 
PPTX
Intro to Python Programming Language
Dipankar Achinta
 
PPTX
Python basics
Hoang Nguyen
 
Introduction to Python - Part Two
amiable_indian
 
Python ppt
Anush verma
 
Python second ppt
RaginiJain21
 
An Introduction : Python
Raghu Kumar
 
Python Basics
tusharpanda88
 
Introduction to the basics of Python programming (part 1)
Pedro Rodrigues
 
Introduction to Python - Part Three
amiable_indian
 
Chapter 9 python fundamentals
Praveen M Jigajinni
 
Fundamentals of Python Programming
Kamal Acharya
 
Python programming
Ashwin Kumar Ramasamy
 
Python Basics
Adheetha O. V
 
Python-04| Fundamental data types vs immutability
Mohd Sajjad
 
Introduction To Programming with Python
Sushant Mane
 
Python for data science by www.dmdiploma.com
ShwetaAggarwal56
 
Learn Python The Hard Way Presentation
Amira ElSharkawy
 
Let’s Learn Python An introduction to Python
Jaganadh Gopinadhan
 
Intro to Python Programming Language
Dipankar Achinta
 
Python basics
Hoang Nguyen
 

Similar to Python basics (20)

PPTX
Introduction to learn and Python Interpreter
Alamelu
 
PPTX
Python (Data Analysis) cleaning and visualize
IruolagbePius
 
PPTX
Python 3.pptx
HarishParthasarathy4
 
ODP
Python slide.1
Aswin Krishnamoorthy
 
PPTX
Keep it Stupidly Simple Introduce Python
SushJalai
 
PPTX
Chapter1 python introduction syntax general
ssuser77162c
 
PPTX
PPt Revision of the basics of python1.pptx
tcsonline1222
 
PPTX
Learn about Python power point presentation
omsumukh85
 
PPTX
Python knowledge ,......................
sabith777a
 
PPTX
1. python programming
sreeLekha51
 
DOCX
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
faithxdunce63732
 
PPTX
Python.pptx
Ankita Shirke
 
PPTX
MODULE. .pptx
Alpha337901
 
PDF
Sessisgytcfgggggggggggggggggggggggggggggggg
pawankamal3
 
PPTX
Introduction on basic python and it's application
sriram2110
 
PPTX
introduction to python programming concepts
GautamDharamrajChouh
 
PDF
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
manikamr074
 
PPTX
python
ultragamer6
 
PPTX
Python for Beginners(v1)
Panimalar Engineering College
 
PDF
An overview on python commands for solving the problems
Ravikiran708913
 
Introduction to learn and Python Interpreter
Alamelu
 
Python (Data Analysis) cleaning and visualize
IruolagbePius
 
Python 3.pptx
HarishParthasarathy4
 
Python slide.1
Aswin Krishnamoorthy
 
Keep it Stupidly Simple Introduce Python
SushJalai
 
Chapter1 python introduction syntax general
ssuser77162c
 
PPt Revision of the basics of python1.pptx
tcsonline1222
 
Learn about Python power point presentation
omsumukh85
 
Python knowledge ,......................
sabith777a
 
1. python programming
sreeLekha51
 
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
faithxdunce63732
 
Python.pptx
Ankita Shirke
 
MODULE. .pptx
Alpha337901
 
Sessisgytcfgggggggggggggggggggggggggggggggg
pawankamal3
 
Introduction on basic python and it's application
sriram2110
 
introduction to python programming concepts
GautamDharamrajChouh
 
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
manikamr074
 
python
ultragamer6
 
Python for Beginners(v1)
Panimalar Engineering College
 
An overview on python commands for solving the problems
Ravikiran708913
 
Ad

Recently uploaded (20)

PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Ad

Python basics

  • 2.  Introduction-  What is Python?  Python History  Features of Python  Applications of Python  Architecture and Working of Python  Python Constructs  Python vs Java vs C++
  • 3.  Python is a General Purpose object-oriented programming language, which means that it can model real-world entities. It is also dynamically-typed because it carries out type-checking at runtime.  Python is an interpreted language.
  • 4.  Guido van Rossum named it after the comedy group Monty Python
  • 5.  Python was developed in the late 1980s and was named after the BBC TV show Monty Python’s Flying Circus.  Guido van Rossum started implementing Python at CWI in the Netherlands in December of 1989.  This was a successor to the ABC programming language which was capable of exception handling and interfacing with the Amoeba operating system.  On October 16 of 2000, Python 2.0 released with many new features.  Then Python 3.0 released on December 3, 2008
  • 6.  Python is the “most powerful language you can still read”, Says Paul Dubois  Python is one of the richest Programming languages.  Going by the TIOBE Index, it is the Second Most Popular Programming Language in the world.
  • 7.  Easy When writing code in Python, you need fewer lines of code compared to languages like Java.  Interpreted It is interpreted(executed) line by line. This makes it easy to test and debug.  Object-Oriented The Python programming language supports classes and objects and hence it is object- oriented.
  • 8.  Free and Open Source The language and its source code are available to the public for free; there is no need to buy a costly license.  Portable Since Python is open-source, you can run it on Windows, Mac, Linux or any other platform. Your programs will work without any need to change it for every machine.  GUI Programming You can use it to develop a GUI (Graphical User Interface). One way to do this is through Tkinter.  Large Python Library Python provides you with a large standard library. You can use it to implement a variety of functions without the need to reinvent the wheel every time. Just pick the code you need and continue
  • 9.  Build a website using Python  Develop a game in Python  Perform Computer Vision (Facilities like face- detection and color-detection)  Implement Machine Learning (Give a computer the ability to learn)  Enable Robotics with Python  Perform Web Scraping (Harvest data from websites)  Perform Data Analysis using Python  Automate a web browser  Perform Scripting in Python  Build Artificial Intelligence
  • 10.  Parser It uses the source code to generate an abstract syntax tree.  Compiler It turns the abstract syntax tree into Python bytecode.  Interpreter It executes the code line by line in a REPL (Read-Evaluate-Print-Loop) fashion.
  • 11.  Functions in Python  Classes in Python  Module Packages in Python  Packages in Python  List in Python  Tuple in Python  Dictionary in Python  Comments and Docstrings in Python(#, ’’ ’’ “)
  • 12.  How does Python get its name?  What are the Features of Python that make it so popular?  Define Modules in Python?  What is the difference between List and Tuple in Python?  Compare Python with Java
  • 13.  A variable is a container for a value. It can be assigned a name, you can use it to refer to it later in the program.  Based on the value assigned, the interpreter decides its data type.  x=45 type =integer  Name=“seed” type = string  List1=[1,22,33] type = list
  • 14.  A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume).  Rules for Python variables: 1. A variable name must start with a letter or the underscore character 2. A variable name cannot start with a number 3. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) 4. Variable names are case-sensitive (age, Age and AGE are three different variables)
  • 15. Valid Variable Names Invalid Variable Names  myval = “Krushna" my_val = “krushna" _my_val = “krushna" myVal = ’krushna’ MYVAL = “krushna" myval2 = “Krushna“  Roll_no =23  rollno1 = 45  Inavlid Variable Names:  2myval = “hello" my-var = “hello" my var = “hello“  roll&no = 45
  • 16.  assign a value to Python variables, you don’t need to declare its type  type the value after the equal sign(=).  You cannot use Python variables before assigning it a value.  You can’t put the identifier on the right-hand side of the equal sign, though. The following code causes an error.  You can’t assign Python variables to a keyword.
  • 17.  You can assign values to multiple Python variables in one statement. 1. pin, city=11,‘Pune' print(pin , city) 2. a,b,c = 11,22,33 print(a) print(b) print(c)  you can assign the same value to multiple Python variables.  a=b=7 print(a,b)
  • 18.  You can also delete Python variables using the keyword ‘del’. a='red' del a
  • 19.  Python has five standard data types − Numbers String List Tuple Dictionary
  • 20.  Number data types store numeric values. Number objects are created when you assign a value to them. For example − var1 = 1 var2 = 70  Python supports four different numerical types − 1. int (signed integers) 2. float (floating point real values) 3. complex (complex numbers)
  • 21. x = 11 # int y = 2.85 # float z = 4+1j # complex Float can also be scientific numbers with an "e" to indicate the power of 10. x = 35e3 # float y = 12E4 # float z = -87.7e100 #float
  • 22. You can convert from one type to another with the int(), float(), and complex() methods: x = 1 # int y = 2.8 # float z = 1j # complex #convert from int to float: a = float(x) #convert from float to int: b = int(y) #convert from int to complex: c = complex(x)  Note: You cannot convert complex numbers into another number type. x = str("s1") # x will be 's1‘ y = str(2) # y will be '2‘ z = str(3.0) # z will be '3.0'
  • 23.  isinstance() function to tell if Python variables belong to a particular class. It takes two parameters- the variable/value, and the class.  >>> print(isinstance(a,complex))
  • 24.  2. Strings A string is a sequence of characters. Python does not have a char data type, unlike C++ or Java. You can delimit a string using single quotes or double-quotes.  >>> city='Ahmednagar'  >>> city
  • 25.  What do you mean by scope?  What are the types of variable scope?  What is scope of variable with example?  What are python variables?  How do you declare a variable in Python 3?
  • 26. Operator Name Example + Addition a+b - Subtraction a-y * Multiplication a*y / Division a / b % Modulus a % b ** Exponentiation a ** b // Floor division a //b
  • 27. Operator Example Same As = x = 5 x = 5 += x += 3 x = x + 3 -= x -= 3 x = x - 3 *= x *= 3 x = x * 3 /= x /= 3 x = x / 3 %= x %= 3 x = x % 3 //= x //= 3 x = x // 3 **= x **= 3 x = x ** 3 |= x |= 3 x = x | 3
  • 28. 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
  • 29. 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)
  • 30.  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
  • 31.  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
  • 32.  Bitwise operators are used to compare (binary) numbers:  Operator Name Description & Binary AND Sets each bit to 1 if both bits are 1 | Binary OR Sets each bit to 1 if one of two bits is 1 ^ Binary XOR Sets each bit to 1 if only one of two bits is 1 ~ Binary 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
  • 33. 1. 5 & 2 => 0101 & 0010 =>0000 2. 5 | 2 => 0101 & 0010 =>0101 3. 5 ^ 3 => 0101 & 0011 =>0110 4. ~5 => ~ 0101 => 1010 5. 10<<1 => 1010<<1 => 10100 6. 10>>1 => 1010 >>1 => 00101
  • 34.  Strings in Python are identified as a contiguous set of characters represented in the quotation marks.  strings in Python are arrays of bytes representing unicode characters.  Python allows for either pairs of single or double quotes print("Hello") print(‘Hello’)  Assign String to a Variable a = "Hello" print(a)
  • 35.  You can assign a multiline string to a variable by using three single or double quotes:  Example ◦ Name = “ ” ” Hello,I am an Interpreter “ “ “ ◦ print(Name) ◦ Name = ‘ ‘ ‘ Hello,I am an Interpreter ’ ’ ’ ◦ print(Name)
  • 36.  str = 'Hello World!'  print (str) # Prints complete string  print str * 2 # Prints string two times  print str + "TEST" # Prints concatenated string
  • 37.  You can return a range of characters by using the slice  Specify the start index and the end index, separated by a colon, to return a part of the string. To display only a part of a string ,use the slicing operator [].  print(str[0]) # Prints first character of the string at 0th index or position  print str[2:5] # Prints characters starting from 2nd to 4th character  print str[2:] # Prints string starting from 2nd character  Note: The first character has index 0.
  • 38.  print(b[:5]) # print the characters from the start to position 5 (not included)  print(b[2:]) # print the characters from position 2, and to the end  Use negative indexes to start the slice from the end of the string  print(b[-5:-2]) # H E L L O 7 [0] [1] [2] [3] [4] [5] Positive index [-6] [-5] [-4] [-3] [-2] [-1] Negative index
  • 39.  Python Strings can join using the concatenation operator +.  a='Do you see this, '  b='$$?' a+b  a='10' print(2*a)