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

What's hot

Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
Devashish Kumar
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
Mohammed Sikander
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
Devashish Kumar
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
PyData
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
hydpy
 
Python tuple
Python   tuplePython   tuple
Python tuple
Mohammed Sikander
 
Namespaces
NamespacesNamespaces
Namespaces
Sangeetha S
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
Damian T. Gordon
 
Operators in python
Operators in pythonOperators in python
Operators in python
Prabhakaran V M
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
Mohd Sajjad
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
Sujith Kumar
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
Megha V
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
Mohammed Sikander
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
TMARAGATHAM
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
AkshayAggarwal79
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
Srinivas Narasegouda
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | Edureka
Edureka!
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
moazamali28
 
Variables in python
Variables in pythonVariables in python
Variables in python
Jaya Kumari
 

What's hot (20)

Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
 
Python tuple
Python   tuplePython   tuple
Python tuple
 
Namespaces
NamespacesNamespaces
Namespaces
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | Edureka
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Variables in python
Variables in pythonVariables in python
Variables in python
 

Similar to Datatypes in python

Programming with Python
Programming with PythonProgramming with Python
Programming with Python
Rasan Samarasinghe
 
PPS_Unit 4.ppt
PPS_Unit 4.pptPPS_Unit 4.ppt
PPS_Unit 4.ppt
KundanBhatkar
 
Python Session - 3
Python Session - 3Python Session - 3
Python Session - 3
AnirudhaGaikwad4
 
Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in python
sunilchute1
 
Python programming
Python  programmingPython  programming
Python programming
Ashwin Kumar Ramasamy
 
Python 3.pptx
Python 3.pptxPython 3.pptx
Python 3.pptx
HarishParthasarathy4
 
Python cheat-sheet
Python cheat-sheetPython cheat-sheet
Python cheat-sheet
srinivasanr281952
 
Python- strings
Python- stringsPython- strings
Python- strings
Krishna Nanda
 
Pythonppt28 11-18
Pythonppt28 11-18Pythonppt28 11-18
Pythonppt28 11-18
Saraswathi Murugan
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE
Saraswathi Murugan
 
1. python programming
1. python programming1. python programming
1. python programming
sreeLekha51
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
 
Python lab basics
Python lab basicsPython lab basics
Python lab basics
Abi_Kasi
 
Python course in_mumbai
Python course in_mumbaiPython course in_mumbai
Python course in_mumbai
vibrantuser
 
Python course in_mumbai
Python course in_mumbaiPython course in_mumbai
Python course in_mumbai
vibrantuser
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha Bali
Akanksha Bali
 
1691912901477_Python_Basics and list,tuple,string.pptx
1691912901477_Python_Basics and list,tuple,string.pptx1691912901477_Python_Basics and list,tuple,string.pptx
1691912901477_Python_Basics and list,tuple,string.pptx
KUSHSHARMA630049
 
python_class.pptx
python_class.pptxpython_class.pptx
python_class.pptx
chandankumar943868
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
Programming Basics.pptx
Programming Basics.pptxProgramming Basics.pptx
Programming Basics.pptx
mahendranaik18
 

Similar to Datatypes in python (20)

Programming with Python
Programming with PythonProgramming with Python
Programming with Python
 
PPS_Unit 4.ppt
PPS_Unit 4.pptPPS_Unit 4.ppt
PPS_Unit 4.ppt
 
Python Session - 3
Python Session - 3Python Session - 3
Python Session - 3
 
Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in python
 
Python programming
Python  programmingPython  programming
Python programming
 
Python 3.pptx
Python 3.pptxPython 3.pptx
Python 3.pptx
 
Python cheat-sheet
Python cheat-sheetPython cheat-sheet
Python cheat-sheet
 
Python- strings
Python- stringsPython- strings
Python- strings
 
Pythonppt28 11-18
Pythonppt28 11-18Pythonppt28 11-18
Pythonppt28 11-18
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE
 
1. python programming
1. python programming1. python programming
1. python programming
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
 
Python lab basics
Python lab basicsPython lab basics
Python lab basics
 
Python course in_mumbai
Python course in_mumbaiPython course in_mumbai
Python course in_mumbai
 
Python course in_mumbai
Python course in_mumbaiPython course in_mumbai
Python course in_mumbai
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha Bali
 
1691912901477_Python_Basics and list,tuple,string.pptx
1691912901477_Python_Basics and list,tuple,string.pptx1691912901477_Python_Basics and list,tuple,string.pptx
1691912901477_Python_Basics and list,tuple,string.pptx
 
python_class.pptx
python_class.pptxpython_class.pptx
python_class.pptx
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
 
Programming Basics.pptx
Programming Basics.pptxProgramming Basics.pptx
Programming Basics.pptx
 

More from eShikshak

Modelling and evaluation
Modelling and evaluationModelling and evaluation
Modelling and evaluation
eShikshak
 
Operators in python
Operators in pythonOperators in python
Operators in python
eShikshak
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
eShikshak
 
Introduction to e commerce
Introduction to e commerceIntroduction to e commerce
Introduction to e commerce
eShikshak
 
Chapeter 2 introduction to cloud computing
Chapeter 2   introduction to cloud computingChapeter 2   introduction to cloud computing
Chapeter 2 introduction to cloud computing
eShikshak
 
Unit 1.4 working of cloud computing
Unit 1.4 working of cloud computingUnit 1.4 working of cloud computing
Unit 1.4 working of cloud computing
eShikshak
 
Unit 1.3 types of cloud
Unit 1.3 types of cloudUnit 1.3 types of cloud
Unit 1.3 types of cloud
eShikshak
 
Unit 1.2 move to cloud computing
Unit 1.2   move to cloud computingUnit 1.2   move to cloud computing
Unit 1.2 move to cloud computing
eShikshak
 
Unit 1.1 introduction to cloud computing
Unit 1.1   introduction to cloud computingUnit 1.1   introduction to cloud computing
Unit 1.1 introduction to cloud computing
eShikshak
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'
eShikshak
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
eShikshak
 
Mesics lecture 7 iteration and repetitive executions
Mesics lecture 7   iteration and repetitive executionsMesics lecture 7   iteration and repetitive executions
Mesics lecture 7 iteration and repetitive executions
eShikshak
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
eShikshak
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
eShikshak
 
Mesics lecture 4 c operators and experssions
Mesics lecture  4   c operators and experssionsMesics lecture  4   c operators and experssions
Mesics lecture 4 c operators and experssionseShikshak
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’eShikshak
 
Mesics lecture 3 c – constants and variables
Mesics lecture 3   c – constants and variablesMesics lecture 3   c – constants and variables
Mesics lecture 3 c – constants and variables
eShikshak
 
Lecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operatorsLecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operators
eShikshak
 
Lecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.pptLecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.ppt
eShikshak
 
Lecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.pptLecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.ppt
eShikshak
 

More from eShikshak (20)

Modelling and evaluation
Modelling and evaluationModelling and evaluation
Modelling and evaluation
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introduction to e commerce
Introduction to e commerceIntroduction to e commerce
Introduction to e commerce
 
Chapeter 2 introduction to cloud computing
Chapeter 2   introduction to cloud computingChapeter 2   introduction to cloud computing
Chapeter 2 introduction to cloud computing
 
Unit 1.4 working of cloud computing
Unit 1.4 working of cloud computingUnit 1.4 working of cloud computing
Unit 1.4 working of cloud computing
 
Unit 1.3 types of cloud
Unit 1.3 types of cloudUnit 1.3 types of cloud
Unit 1.3 types of cloud
 
Unit 1.2 move to cloud computing
Unit 1.2   move to cloud computingUnit 1.2   move to cloud computing
Unit 1.2 move to cloud computing
 
Unit 1.1 introduction to cloud computing
Unit 1.1   introduction to cloud computingUnit 1.1   introduction to cloud computing
Unit 1.1 introduction to cloud computing
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
 
Mesics lecture 7 iteration and repetitive executions
Mesics lecture 7   iteration and repetitive executionsMesics lecture 7   iteration and repetitive executions
Mesics lecture 7 iteration and repetitive executions
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
 
Mesics lecture 4 c operators and experssions
Mesics lecture  4   c operators and experssionsMesics lecture  4   c operators and experssions
Mesics lecture 4 c operators and experssions
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
Mesics lecture 3 c – constants and variables
Mesics lecture 3   c – constants and variablesMesics lecture 3   c – constants and variables
Mesics lecture 3 c – constants and variables
 
Lecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operatorsLecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operators
 
Lecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.pptLecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.ppt
 
Lecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.pptLecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.ppt
 

Recently uploaded

IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 

Recently uploaded (20)

IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 

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