SlideShare a Scribd company logo
Datatypes in Python
Prakash G Khaire
The Mandvi Education Society
Institute of Computer Studies
Comments in Python
• Single Line Comments
• Comments are non-executable statements.
• Python compiler nor PVM will execute them.
#To find the sum of two numbers
a = 10 # store 10 into variable a
Comments in Python
• When we want to mark several lines as comment, then we can write the previous
block of code inside ””” (triple double quotes) or ’’’ (triple single quotes) in the
beginning and ending of the block as.
”””
Write a program to find the total marks scored by a
student in the subjects
”””
’’’
Write a program to find the total marks scored by a
student in the subjects
’’’
Comments in Python
• Python supports only single line comments.
• Multiline comments are not available in Python.
• Triple double quotes or triple single quotes
are actually not multiline comments but they are regular
strings with the exception that they can span
multiple lines.
• Use of ’’’ or ””” are not recommended for comments as
they internally occupy memory.
Variables
• In many languages, the concept of variable is
connected to memory location.
• In python, a variable is seen as a tag that is tied to
some value.
• Variable names in Python can be any length.
• It can consist of uppercase and lowercase letters (A-Z,
a-z), digits (0-9), and the underscore character (_).
• A restriction is that, a variable name can contain digits,
the first character of a variable name cannot be a
digit.
Datatypes in Python
• A datatype represents the type of data stored
into a variable or memory.
• The datatypes which are already avaiable in
Python language are called Built-in datatypes.
• The datatypes which are created by the
programmers are called User-Defined
datatypes.
Built-in datatypes
• None Type
• Numeric Types
• Sequences
• Sets
• Mappings
None Type
• ‘None’ datatype represents an object that does not contain
any value.
• In Java, it is called ‘Null’ Object’, but in Python it is called
‘None’ object.
• In Python program, maximum of only one ‘None’ object is
provided.
• ‘None’ type is used inside a function as a default value of the
arguments.
• When calling the function, if no value is passed, then the
default value will be taken as ‘None’.
• In Boolean expressions, ‘None’ datatype is represents ‘False’
Numeric Types
• int
• float
• complex
int Datatype
• The int datatype represents an integer number.
• An integer number is a number without any
decimal point or fraction part.
•
int datatype supports both negative and positive
integer numbers.
• It can store very large integer numbers
conveniently.
a = 10
b = -15
Float datatype
• The float datatype represents floating point numbers.
• A floating point number is a number that contains a decimal
point.
#For example : 0.5, -3.4567, 290.08,0.001
num = 123.45
x = 22.55e3
#here the float value is 22.55 x 103
bool Datatype
• The bool datatype in Python represents
boolean values.
• There are only two boolean values True or
False that can be represented by this
datatype.
• Python internally represents True as 1 and
False as 0.
Print Statement
>>>print “Python"
Python
>>>print “Python Programming"
Python Programming
>>> print "Hi, I am Learning Python Programming."
Hi, I am Learning Python Programming.
Print Statement
>>> print 25
25
>>> print 2*2
4
>>> print 2 + 5 + 9
16
Print Statement
>>> print "Hello,","I","am",“Python"
Hello, I am Python
>>> print “Python","is",27,"years","old"
Python is 27 years old
>>> print 1,2,3,4,5,6,7,8,9,0
1 2 3 4 5 6 7 8 9 0
Print Statement
>>> print "Hello Python, " + "How are you?"
Hello Python, How are you?
>>> print "I am 20 Years old " + "and" + " My friend is 21 years old.“
I am 20 Years old and My friend is 21 years old.
Sequences in Python
• A sequence represents a group of elements or items.
• There are six types of sequences in Python
– str
– bytes
– bytearray
– list
– tuple
– range
str datatype
• A string is represented by a group of characters. Strings are
enclosed in single quotes or double quotes.
• We can also write string inside “““ (triple double quotes) or ‘‘‘
(single double quotes)
str = “Welcome to TMES”
str = ‘Welcome to TMES’
str1 = “““ This is book on python which discusses all the topics of Core python
in a very lucid manner.”””
str1 = ‘‘‘This is book on python which discusses all the topics of Core python in
a very lucid manner.’’’
str datatype
str1 = “““ This is ‘Core Python’ book.”””
print(str1) # This is ‘Core Python’ book.
str1 = ‘‘‘This is ‘Core Python’ book.’’’
print(str1) # This is ‘Core Python’ book.
s = ‘Welcome to Core Python’
print(s[0]) #display 0th character from s
W
print(s[3:7]) #display from 3rd to 6th character
come
print(s[11:]) #display from 11th characters onwards till end.
Core Python
print(s[-1]) #display first character from the end
n
str datatype
• The repetition operator is denoted by ‘*’ symbol and useful to
repeat the string for several times. For example s * n repeats
the string for n times.
print(s*2)
Welcome to Core PythonWelcome to Core Python
bytes Datatype
• A byte number is any positive integer from 0 to
255.
• Bytes array can store numbers in the range from
0 to 255 and it cannot even storage.
• We can modify or edit any element in the bytes
type array.
elements = [10, 20, 0, 40, 15] #this is a list of byte numbers
x = bytes(elements) #convert the list into byte array
print(x[10]) #display 0th element, i.e 10
list Datatype
• Lists in Python are similar to arrays in C or Java.
• The main difference between a list an array is that a list can
store different types of elements, but array can store only one
type of elements.
• List can grow dynamically in memory.
• But the size of arrays is fixed and they cannot grow at
runtime.
list = [10, -20, 15.5, ‘vijay’, “Marry”]
list Datatype
• The slicing operation like [0:3] represents elements from 0th to
2nd positions. i.e 10,20,15.5
>>>list = [10, -20, 15.5, ‘vijay’, “Marry”]
>>>print(list)
10, -20, 15.5, ‘vijay’, “Marry”
>>> print(list[0])
10
>>>print(list[1:3])
[-20,15.5]
>>>print(list[-2])
vijay
>>>print(list*2)
[ 10, -20, 15.5, ‘vijay’, “Marry” 10, -20, 15.5, ‘vijay’, “Marry”]
tuple datatype
• A tuple contains a group of elements which
can be of different types.
• The elements in the tuple are separated by
commas and enclosed in parentheses().
• It is not possible to modify the tuple elements.
tpl = (10, -20, 15.5, ‘Vijay’ , “Marry”)
tuple datatype
>>> tpl = (10,-20,14.5, "Prakash", 'Khaire')
>>> print(tpl)
(10, -20, 14.5, 'Prakash', 'Khaire')
>>> print(tpl[1:3])
(-20, 14.5)
>>> print(tpl[0])
10
>>> print(tpl[-1])
Khaire
>>> print(tpl*2)
(10, -20, 14.5, 'Prakash', 'Khaire', 10, -20, 14.5, 'Prakash', 'Khaire')
>>> tpl[0] = 1
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
tpl[0] = 1
TypeError: 'tuple' object does not support item assignment
range Datatype
• The range datatype represents a sequence of
numbers.
• The numbers is the range are not modifiable.
• Range is used for repeating a for loop for a
specific number of times.
range Datatype
>>> r = range(10)
>>> for i in r : print(i)
0
1
2
3
4
5
6
7
8
9
range Datatype
>>> r = range(30,40,2)
>>> for i in r:print(i)
30
32
34
36
38
>>> lst = list(range(10))
>>>
>>> print(lst)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Sets
• A set is an unordered collection of elements muck like
a set in Mathematics.
• The order of elements is not maintained in the sets.
• It means the elements may not appear in the same
order as they are entered into the set.
• A set does not accept duplicate elements.
• There are two sub types in sets
– Set datatype
– Frozenset datatype
Sets
• To create a set, we should enter the elements separated by
commas inside curly braces {}.
s = {10, 20, 30, 20, 50}
>>> print(s)
{10, 20, 50, 30}
ch = set("Python")
>>> print(ch)
{'n', 'h', 't', 'o', 'P', 'y'}
>>> lst = [1,2,4,3,5]
>>> s = set(lst)
>>> print(s)
{1, 2, 3, 4, 5}
Sets
• To create a set, we should enter the elements separated by
commas inside curly braces {}.
s = {10, 20, 30, 20, 50}
>>> print(s)
{10, 20, 50, 30}
ch = set("Python")
>>> print(ch)
{'n', 'h', 't', 'o', 'P', 'y'}
>>> lst = [1,2,4,3,5]
>>> s = set(lst)
>>> print(s)
{1, 2, 3, 4, 5}
Sets
>>> print(s[0])
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
print(s[0])
TypeError: 'set' object does not support indexing
>>> s.update([110,200])
>>> print(s)
{1, 2, 3, 4, 5, 200, 110}
>>> s.remove(4)
>>> print(s)
{1, 2, 3, 5, 200, 110}
frozenset Datatype
• The frozenset datatype is same as the set datatype.
• The main difference is that the elements in the set datatype
can be modified.
• The elements of the frozenset cannot be modified.
>>> s = {20,40,60,10,30,50}
>>> print(s)
{40, 10, 50, 20, 60, 30}
>>> fs = frozenset(s)
>>> print(s)
{40, 10, 50, 20, 60, 30}
frozenset Datatype
• The frozenset datatype is same as the set datatype.
• The main difference is that the elements in the set datatype can be
modified.
• The elements of the frozenset cannot be modified.
>>> s = {20,40,60,10,30,50}
>>> print(s)
{40, 10, 50, 20, 60, 30}
>>> fs = frozenset(s)
>>> print(s)
{40, 10, 50, 20, 60, 30}
>>> fs = frozenset("Python")
>>> print(fs)
frozenset({'n', 'h', 't', 'o', 'P', 'y'})
What is ?
• Mapping Types
• Literals
• type function

More Related Content

PPTX
Data types in python
RaginiJain21
 
PPTX
Introduction to python for Beginners
Sujith Kumar
 
PPTX
Python Functions
Mohammed Sikander
 
PPTX
List in Python
Siddique Ibrahim
 
PDF
Python functions
Prof. Dr. K. Adisesha
 
PPTX
Python variables and data types.pptx
AkshayAggarwal79
 
PDF
Python list
Mohammed Sikander
 
PPTX
Variables in python
Jaya Kumari
 
Data types in python
RaginiJain21
 
Introduction to python for Beginners
Sujith Kumar
 
Python Functions
Mohammed Sikander
 
List in Python
Siddique Ibrahim
 
Python functions
Prof. Dr. K. Adisesha
 
Python variables and data types.pptx
AkshayAggarwal79
 
Python list
Mohammed Sikander
 
Variables in python
Jaya Kumari
 

What's hot (20)

PPTX
Values and Data types in python
Jothi Thilaga P
 
PDF
Lesson 02 python keywords and identifiers
Nilimesh Halder
 
PPTX
Datastructures in python
hydpy
 
PDF
Python exception handling
Mohammed Sikander
 
PDF
Strings in python
Prabhakaran V M
 
PPTX
Python Exception Handling
Megha V
 
PDF
Python-03| Data types
Mohd Sajjad
 
PPTX
Looping statement in python
RaginiJain21
 
PPTX
Constructor ppt
Vinod Kumar
 
PPTX
Python Seminar PPT
Shivam Gupta
 
PDF
Python - the basics
University of Technology
 
PPTX
Python: Modules and Packages
Damian T. Gordon
 
PPTX
Function in C program
Nurul Zakiah Zamri Tan
 
PPTX
linked list in data structure
shameen khan
 
PPTX
Data Structures in Python
Devashish Kumar
 
PDF
Python programming : Files
Emertxe Information Technologies Pvt Ltd
 
PPTX
Python
Aashish Jain
 
PPTX
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
ODP
Python Modules
Nitin Reddy Katkam
 
Values and Data types in python
Jothi Thilaga P
 
Lesson 02 python keywords and identifiers
Nilimesh Halder
 
Datastructures in python
hydpy
 
Python exception handling
Mohammed Sikander
 
Strings in python
Prabhakaran V M
 
Python Exception Handling
Megha V
 
Python-03| Data types
Mohd Sajjad
 
Looping statement in python
RaginiJain21
 
Constructor ppt
Vinod Kumar
 
Python Seminar PPT
Shivam Gupta
 
Python - the basics
University of Technology
 
Python: Modules and Packages
Damian T. Gordon
 
Function in C program
Nurul Zakiah Zamri Tan
 
linked list in data structure
shameen khan
 
Data Structures in Python
Devashish Kumar
 
Python programming : Files
Emertxe Information Technologies Pvt Ltd
 
Python
Aashish Jain
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
Python Modules
Nitin Reddy Katkam
 
Ad

Similar to Datatypes in python (20)

PPTX
Keep it Stupidly Simple Introduce Python
SushJalai
 
PPSX
Programming with Python
Rasan Samarasinghe
 
PPT
PPS_Unit 4.ppt
KundanBhatkar
 
PPTX
Python Session - 3
AnirudhaGaikwad4
 
PPTX
Introduction to learn and Python Interpreter
Alamelu
 
PPTX
funadamentals of python programming language (right from scratch)
MdFurquan7
 
PPTX
Basic data types in python
sunilchute1
 
PPTX
Python programming
Ashwin Kumar Ramasamy
 
PPTX
IOT notes,................................
taetaebts431
 
PPTX
Python 3.pptx
HarishParthasarathy4
 
PDF
Python cheat-sheet
srinivasanr281952
 
PDF
Python- strings
Krishna Nanda
 
PPTX
Pythonppt28 11-18
Saraswathi Murugan
 
PPTX
FUNDAMENTALS OF PYTHON LANGUAGE
Saraswathi Murugan
 
PPTX
1. python programming
sreeLekha51
 
PPTX
introduction to python programming concepts
GautamDharamrajChouh
 
PPTX
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
 
PPT
Python lab basics
Abi_Kasi
 
PPTX
Review old Pygame made using python programming.pptx
ithepacer
 
PPT
Python course in_mumbai
vibrantuser
 
Keep it Stupidly Simple Introduce Python
SushJalai
 
Programming with Python
Rasan Samarasinghe
 
PPS_Unit 4.ppt
KundanBhatkar
 
Python Session - 3
AnirudhaGaikwad4
 
Introduction to learn and Python Interpreter
Alamelu
 
funadamentals of python programming language (right from scratch)
MdFurquan7
 
Basic data types in python
sunilchute1
 
Python programming
Ashwin Kumar Ramasamy
 
IOT notes,................................
taetaebts431
 
Python 3.pptx
HarishParthasarathy4
 
Python cheat-sheet
srinivasanr281952
 
Python- strings
Krishna Nanda
 
Pythonppt28 11-18
Saraswathi Murugan
 
FUNDAMENTALS OF PYTHON LANGUAGE
Saraswathi Murugan
 
1. python programming
sreeLekha51
 
introduction to python programming concepts
GautamDharamrajChouh
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
 
Python lab basics
Abi_Kasi
 
Review old Pygame made using python programming.pptx
ithepacer
 
Python course in_mumbai
vibrantuser
 
Ad

More from eShikshak (20)

PDF
Modelling and evaluation
eShikshak
 
PDF
Operators in python
eShikshak
 
PDF
Introduction to python
eShikshak
 
PPT
Introduction to e commerce
eShikshak
 
PDF
Chapeter 2 introduction to cloud computing
eShikshak
 
PDF
Unit 1.4 working of cloud computing
eShikshak
 
PDF
Unit 1.3 types of cloud
eShikshak
 
PDF
Unit 1.2 move to cloud computing
eShikshak
 
PDF
Unit 1.1 introduction to cloud computing
eShikshak
 
PPT
Mesics lecture files in 'c'
eShikshak
 
PPT
Mesics lecture 8 arrays in 'c'
eShikshak
 
PPT
Mesics lecture 7 iteration and repetitive executions
eShikshak
 
PPT
Mesics lecture 5 input – output in ‘c’
eShikshak
 
PPT
Mesics lecture 6 control statement = if -else if__else
eShikshak
 
PPT
Mesics lecture 4 c operators and experssions
eShikshak
 
PPT
Mesics lecture 5 input – output in ‘c’
eShikshak
 
PPT
Mesics lecture 3 c – constants and variables
eShikshak
 
PDF
Lecture 7 relational_and_logical_operators
eShikshak
 
PDF
Lecture21 categoriesof userdefinedfunctions.ppt
eShikshak
 
PDF
Lecture20 user definedfunctions.ppt
eShikshak
 
Modelling and evaluation
eShikshak
 
Operators in python
eShikshak
 
Introduction to python
eShikshak
 
Introduction to e commerce
eShikshak
 
Chapeter 2 introduction to cloud computing
eShikshak
 
Unit 1.4 working of cloud computing
eShikshak
 
Unit 1.3 types of cloud
eShikshak
 
Unit 1.2 move to cloud computing
eShikshak
 
Unit 1.1 introduction to cloud computing
eShikshak
 
Mesics lecture files in 'c'
eShikshak
 
Mesics lecture 8 arrays in 'c'
eShikshak
 
Mesics lecture 7 iteration and repetitive executions
eShikshak
 
Mesics lecture 5 input – output in ‘c’
eShikshak
 
Mesics lecture 6 control statement = if -else if__else
eShikshak
 
Mesics lecture 4 c operators and experssions
eShikshak
 
Mesics lecture 5 input – output in ‘c’
eShikshak
 
Mesics lecture 3 c – constants and variables
eShikshak
 
Lecture 7 relational_and_logical_operators
eShikshak
 
Lecture21 categoriesof userdefinedfunctions.ppt
eShikshak
 
Lecture20 user definedfunctions.ppt
eShikshak
 

Recently uploaded (20)

PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Software Development Company | KodekX
KodekX
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PDF
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
CIFDAQ
 
PPTX
The Power of IoT Sensor Integration in Smart Infrastructure and Automation.pptx
Rejig Digital
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Software Development Company | KodekX
KodekX
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
CIFDAQ
 
The Power of IoT Sensor Integration in Smart Infrastructure and Automation.pptx
Rejig Digital
 
This slide provides an overview Technology
mineshkharadi333
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 

Datatypes in python

  • 1. Datatypes in Python Prakash G Khaire The Mandvi Education Society Institute of Computer Studies
  • 2. Comments in Python • Single Line Comments • Comments are non-executable statements. • Python compiler nor PVM will execute them. #To find the sum of two numbers a = 10 # store 10 into variable a
  • 3. Comments in Python • When we want to mark several lines as comment, then we can write the previous block of code inside ””” (triple double quotes) or ’’’ (triple single quotes) in the beginning and ending of the block as. ””” Write a program to find the total marks scored by a student in the subjects ””” ’’’ Write a program to find the total marks scored by a student in the subjects ’’’
  • 4. Comments in Python • Python supports only single line comments. • Multiline comments are not available in Python. • Triple double quotes or triple single quotes are actually not multiline comments but they are regular strings with the exception that they can span multiple lines. • Use of ’’’ or ””” are not recommended for comments as they internally occupy memory.
  • 5. Variables • In many languages, the concept of variable is connected to memory location. • In python, a variable is seen as a tag that is tied to some value. • Variable names in Python can be any length. • It can consist of uppercase and lowercase letters (A-Z, a-z), digits (0-9), and the underscore character (_). • A restriction is that, a variable name can contain digits, the first character of a variable name cannot be a digit.
  • 6. Datatypes in Python • A datatype represents the type of data stored into a variable or memory. • The datatypes which are already avaiable in Python language are called Built-in datatypes. • The datatypes which are created by the programmers are called User-Defined datatypes.
  • 7. Built-in datatypes • None Type • Numeric Types • Sequences • Sets • Mappings
  • 8. None Type • ‘None’ datatype represents an object that does not contain any value. • In Java, it is called ‘Null’ Object’, but in Python it is called ‘None’ object. • In Python program, maximum of only one ‘None’ object is provided. • ‘None’ type is used inside a function as a default value of the arguments. • When calling the function, if no value is passed, then the default value will be taken as ‘None’. • In Boolean expressions, ‘None’ datatype is represents ‘False’
  • 9. Numeric Types • int • float • complex
  • 10. int Datatype • The int datatype represents an integer number. • An integer number is a number without any decimal point or fraction part. • int datatype supports both negative and positive integer numbers. • It can store very large integer numbers conveniently. a = 10 b = -15
  • 11. Float datatype • The float datatype represents floating point numbers. • A floating point number is a number that contains a decimal point. #For example : 0.5, -3.4567, 290.08,0.001 num = 123.45 x = 22.55e3 #here the float value is 22.55 x 103
  • 12. bool Datatype • The bool datatype in Python represents boolean values. • There are only two boolean values True or False that can be represented by this datatype. • Python internally represents True as 1 and False as 0.
  • 13. Print Statement >>>print “Python" Python >>>print “Python Programming" Python Programming >>> print "Hi, I am Learning Python Programming." Hi, I am Learning Python Programming.
  • 14. Print Statement >>> print 25 25 >>> print 2*2 4 >>> print 2 + 5 + 9 16
  • 15. Print Statement >>> print "Hello,","I","am",“Python" Hello, I am Python >>> print “Python","is",27,"years","old" Python is 27 years old >>> print 1,2,3,4,5,6,7,8,9,0 1 2 3 4 5 6 7 8 9 0
  • 16. Print Statement >>> print "Hello Python, " + "How are you?" Hello Python, How are you? >>> print "I am 20 Years old " + "and" + " My friend is 21 years old.“ I am 20 Years old and My friend is 21 years old.
  • 17. Sequences in Python • A sequence represents a group of elements or items. • There are six types of sequences in Python – str – bytes – bytearray – list – tuple – range
  • 18. str datatype • A string is represented by a group of characters. Strings are enclosed in single quotes or double quotes. • We can also write string inside “““ (triple double quotes) or ‘‘‘ (single double quotes) str = “Welcome to TMES” str = ‘Welcome to TMES’ str1 = “““ This is book on python which discusses all the topics of Core python in a very lucid manner.””” str1 = ‘‘‘This is book on python which discusses all the topics of Core python in a very lucid manner.’’’
  • 19. str datatype str1 = “““ This is ‘Core Python’ book.””” print(str1) # This is ‘Core Python’ book. str1 = ‘‘‘This is ‘Core Python’ book.’’’ print(str1) # This is ‘Core Python’ book. s = ‘Welcome to Core Python’ print(s[0]) #display 0th character from s W print(s[3:7]) #display from 3rd to 6th character come print(s[11:]) #display from 11th characters onwards till end. Core Python print(s[-1]) #display first character from the end n
  • 20. str datatype • The repetition operator is denoted by ‘*’ symbol and useful to repeat the string for several times. For example s * n repeats the string for n times. print(s*2) Welcome to Core PythonWelcome to Core Python
  • 21. bytes Datatype • A byte number is any positive integer from 0 to 255. • Bytes array can store numbers in the range from 0 to 255 and it cannot even storage. • We can modify or edit any element in the bytes type array. elements = [10, 20, 0, 40, 15] #this is a list of byte numbers x = bytes(elements) #convert the list into byte array print(x[10]) #display 0th element, i.e 10
  • 22. list Datatype • Lists in Python are similar to arrays in C or Java. • The main difference between a list an array is that a list can store different types of elements, but array can store only one type of elements. • List can grow dynamically in memory. • But the size of arrays is fixed and they cannot grow at runtime. list = [10, -20, 15.5, ‘vijay’, “Marry”]
  • 23. list Datatype • The slicing operation like [0:3] represents elements from 0th to 2nd positions. i.e 10,20,15.5 >>>list = [10, -20, 15.5, ‘vijay’, “Marry”] >>>print(list) 10, -20, 15.5, ‘vijay’, “Marry” >>> print(list[0]) 10 >>>print(list[1:3]) [-20,15.5] >>>print(list[-2]) vijay >>>print(list*2) [ 10, -20, 15.5, ‘vijay’, “Marry” 10, -20, 15.5, ‘vijay’, “Marry”]
  • 24. tuple datatype • A tuple contains a group of elements which can be of different types. • The elements in the tuple are separated by commas and enclosed in parentheses(). • It is not possible to modify the tuple elements. tpl = (10, -20, 15.5, ‘Vijay’ , “Marry”)
  • 25. tuple datatype >>> tpl = (10,-20,14.5, "Prakash", 'Khaire') >>> print(tpl) (10, -20, 14.5, 'Prakash', 'Khaire') >>> print(tpl[1:3]) (-20, 14.5) >>> print(tpl[0]) 10 >>> print(tpl[-1]) Khaire >>> print(tpl*2) (10, -20, 14.5, 'Prakash', 'Khaire', 10, -20, 14.5, 'Prakash', 'Khaire') >>> tpl[0] = 1 Traceback (most recent call last): File "<pyshell#6>", line 1, in <module> tpl[0] = 1 TypeError: 'tuple' object does not support item assignment
  • 26. range Datatype • The range datatype represents a sequence of numbers. • The numbers is the range are not modifiable. • Range is used for repeating a for loop for a specific number of times.
  • 27. range Datatype >>> r = range(10) >>> for i in r : print(i) 0 1 2 3 4 5 6 7 8 9
  • 28. range Datatype >>> r = range(30,40,2) >>> for i in r:print(i) 30 32 34 36 38 >>> lst = list(range(10)) >>> >>> print(lst) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  • 29. Sets • A set is an unordered collection of elements muck like a set in Mathematics. • The order of elements is not maintained in the sets. • It means the elements may not appear in the same order as they are entered into the set. • A set does not accept duplicate elements. • There are two sub types in sets – Set datatype – Frozenset datatype
  • 30. Sets • To create a set, we should enter the elements separated by commas inside curly braces {}. s = {10, 20, 30, 20, 50} >>> print(s) {10, 20, 50, 30} ch = set("Python") >>> print(ch) {'n', 'h', 't', 'o', 'P', 'y'} >>> lst = [1,2,4,3,5] >>> s = set(lst) >>> print(s) {1, 2, 3, 4, 5}
  • 31. Sets • To create a set, we should enter the elements separated by commas inside curly braces {}. s = {10, 20, 30, 20, 50} >>> print(s) {10, 20, 50, 30} ch = set("Python") >>> print(ch) {'n', 'h', 't', 'o', 'P', 'y'} >>> lst = [1,2,4,3,5] >>> s = set(lst) >>> print(s) {1, 2, 3, 4, 5}
  • 32. Sets >>> print(s[0]) Traceback (most recent call last): File "<pyshell#7>", line 1, in <module> print(s[0]) TypeError: 'set' object does not support indexing >>> s.update([110,200]) >>> print(s) {1, 2, 3, 4, 5, 200, 110} >>> s.remove(4) >>> print(s) {1, 2, 3, 5, 200, 110}
  • 33. frozenset Datatype • The frozenset datatype is same as the set datatype. • The main difference is that the elements in the set datatype can be modified. • The elements of the frozenset cannot be modified. >>> s = {20,40,60,10,30,50} >>> print(s) {40, 10, 50, 20, 60, 30} >>> fs = frozenset(s) >>> print(s) {40, 10, 50, 20, 60, 30}
  • 34. frozenset Datatype • The frozenset datatype is same as the set datatype. • The main difference is that the elements in the set datatype can be modified. • The elements of the frozenset cannot be modified. >>> s = {20,40,60,10,30,50} >>> print(s) {40, 10, 50, 20, 60, 30} >>> fs = frozenset(s) >>> print(s) {40, 10, 50, 20, 60, 30} >>> fs = frozenset("Python") >>> print(fs) frozenset({'n', 'h', 't', 'o', 'P', 'y'})
  • 35. What is ? • Mapping Types • Literals • type function