SlideShare a Scribd company logo
Akhil Kaushik
Asstt. Prof., CE Deptt.,
TIT Bhiwani
Data Types in Python
Python Introduction
• Python is a dynamic-typed language (uses interpreter).
• Many other languages are static typed, such as C/C++
and Java (use compiler).
• A static typed language requires the programmer to
explicitly tell the computer what type of “thing” each
data value is.
Python Introduction
• In Python, you simply give your variables names
and assign values to them.
• The interpreter takes care of keeping track of what
kinds of objects your program is using.
• This also means that you can change the size of
the values as you develop the program.
Names and Tokens
• Identifiers can be of unlimited length.
• Names and identifiers are case sensitive.
• Allowed characters: a-z, A-Z, 0-9 & underscore.
• It must begin with a letter or underscore.
• Names/variables in Python do not have a type.
Values have types.
Names and Tokens
• Naming conventions Not rigid, but:
–Modules and packages - all lower case.
–Global and constants – Upper case.
–Classes - caps with initial upper.
–Methods and functions – All lower case with words
separated by underscores.
–Local variables - Lowercase (with underscore
between words) or bumpy caps with initial lower or
your choice.
Blocks and Indentation
• Python represents block structure
and nested block structure with
indentation, not with begin and
end brackets.
• Indentation is 4 spaces and no
hard tabs.
• Reduces clutter. Eliminates all the
curly brackets.
Modules & Packages
• Modules correspond to files with a "*.py"
extension.
• Packages correspond to a directory (or folder) in
the file system; a package contains a file named
"__init__.py". Both modules and packages can be
imported.
• Packages - A directory containing a file named
"__init__.py".
Operators
• Python defines the following operators:
• The comparison operators <> and != are alternate
spellings of the same operator.
• Logical Operators: and, or, not, is, in
Operators’ Precedence
• Table summarizes the
operator precedence in
Python, from lowest
precedence to highest
precedence.
• Operators on the same line
have the same precedence.
• At end, +,-,*, / come.
Data Types
• Numeric Types
• Strings
• Lists
• Tuples
• Dictionaries
• Sets
• Files, Boolean, etc.
Data Types - Numeric
• Python supports 2 types of numbers:
– Integer
Ex: myint = 7
print(myint)
– Float
Ex: myfnt = 7.0
print(myfnt)
myff = float(28)
print(myff)
– complex nos: 3.14j
Data Types - Strings
• Strings in Python are identified as a contiguous set
of characters represented in the quotation marks.
• Python allows either pair of single or double quotes.
• Advantage of using double quotes is that we don’t
need to worry about apostrophes.
• More than 1 variable can be assigned values
simultaneously.
Data Types - Strings
Ex: mys = ‘Hello’
print(mys)
myss = “Mate”
print(myss)
print(mys + “ ”+myss)
Data Types - Strings
• Subsets of strings can be taken using the slice
operator ([ ] and [:] ) with indexes starting at 0 in the
beginning of the string and working their way from -
1 to the end.
• The plus (+) sign is the string concatenation
operator and the asterisk (*) is the repetition
operator.
Data Types - Strings
Data Types - Strings
Data Types – Formatted Strings
f-strings are string
literals that have an ‘f’
at the beginning and
curly braces containing
expressions that will be
replaced with their
values.
Data Types - Lists
• It is like a structure that
may contain different types
of data elements.
• Ex: list1 = [2233, 88.76,
45+6j, “wfh”, 56]
• Ex: list1[2] = “new”
Data Types - Lists
The concept of
slicing can also
be applied here:
Data Types - Lists
Data Types - Tuples
• It is similar to lists, but
once created it cannot
be edited.
• Tuple uses parenthesis
() instead of square
brackets[].
Data Types - Dictionary
• It is an alternate to the switch-case construct and is
used as a key-value pair.
• Each key is separated from its value by a colon (:),
the items are separated by commas, and the whole
thing is enclosed in curly braces.
• An empty dictionary without any items is written
with just two curly braces, like this: {}.
Data Types - Dictionary
Data Types – Boolean
• Boolean type provides two built-in values:
– True and False.
• It denotes by the class bool.
• True can be represented by any non-zero value or
'T' whereas false can be represented by the 0 or 'F'.
• Ex: print(type(True))
• Ex: print(type(False))
Data Types - Sets
• Python Set is the unordered collection of the data
type.
• It is iteratable, mutable(can modify after creation),
and has unique elements.
• In set, the order of the elements is undefined.
• The set is created by using a built-in
function set(), or a sequence of elements is passed
in the curly braces and separated by the comma.
Data Types - Sets
Ex: a = {5,2,3,1,4}
# printing set variable
print("a = ", a)
# data type of variable a
print(type(a))
Data Types - Sets
Ex: set1 = set()
set2 = {'James', 2, 3,'Pyt'}
print(set2)
set2.add(10)
print(set2)
set2.remove(2)
print(set2)
Akhil Kaushik
akhilkaushik05@gmail.com
9416910303
CONTACT ME AT:
Akhil Kaushik
akhilkaushik05@gmail.com
9416910303
THANK YOU !!!

More Related Content

What's hot (20)

PPTX
Python strings presentation
VedaGayathri1
 
PDF
Python list
Mohammed Sikander
 
PPTX
Data Structures in Python
Devashish Kumar
 
PPSX
Modules and packages in python
TMARAGATHAM
 
PPT
Operator Overloading
Nilesh Dalvi
 
PDF
Tuples in Python
DPS Ranipur Haridwar UK
 
PPTX
List in Python
Siddique Ibrahim
 
PDF
Python programming : Control statements
Emertxe Information Technologies Pvt Ltd
 
PDF
Python Class | Python Programming | Python Tutorial | Edureka
Edureka!
 
PPTX
Tuple in python
Sharath Ankrajegowda
 
PPTX
String Manipulation in Python
Pooja B S
 
PDF
Datatypes in python
eShikshak
 
PDF
Python functions
Prof. Dr. K. Adisesha
 
PDF
Python-03| Data types
Mohd Sajjad
 
PPTX
Looping Statements and Control Statements in Python
PriyankaC44
 
PPT
Python List.ppt
T PRIYA
 
PDF
Python tuple
Mohammed Sikander
 
PDF
Function in Python
Yashdev Hada
 
PPTX
Pointer in C++
Mauryasuraj98
 
Python strings presentation
VedaGayathri1
 
Python list
Mohammed Sikander
 
Data Structures in Python
Devashish Kumar
 
Modules and packages in python
TMARAGATHAM
 
Operator Overloading
Nilesh Dalvi
 
Tuples in Python
DPS Ranipur Haridwar UK
 
List in Python
Siddique Ibrahim
 
Python programming : Control statements
Emertxe Information Technologies Pvt Ltd
 
Python Class | Python Programming | Python Tutorial | Edureka
Edureka!
 
Tuple in python
Sharath Ankrajegowda
 
String Manipulation in Python
Pooja B S
 
Datatypes in python
eShikshak
 
Python functions
Prof. Dr. K. Adisesha
 
Python-03| Data types
Mohd Sajjad
 
Looping Statements and Control Statements in Python
PriyankaC44
 
Python List.ppt
T PRIYA
 
Python tuple
Mohammed Sikander
 
Function in Python
Yashdev Hada
 
Pointer in C++
Mauryasuraj98
 

Similar to Python Data-Types (20)

PPTX
2. Values and Data types in Python.pptx
deivanayagamramachan
 
PPTX
1. python programming
sreeLekha51
 
PPTX
Introduction to python
Ayshwarya Baburam
 
PDF
"Automata Basics and Python Applications"
ayeshasiraj34
 
PPTX
Python Tutorial Part 1
Haitham El-Ghareeb
 
PPTX
python presentation.pptx
NightTune44
 
PPTX
Python unit 2 is added. Has python related programming content
swarna16
 
PPTX
Python-Basics.pptx
TamalSengupta8
 
PPTX
Introduction to Python Programming for beginners
MuhammadUsman406079
 
PPTX
Engineering CS 5th Sem Python Module -2.pptx
hardii0991
 
PPTX
introduction to python,datatypes,operators
MrANaveenKumar
 
PPTX
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
 
PPTX
PYTHON PPT.pptx python is very useful for day to day life
NaitikSingh33
 
PPTX
Fundamentals of Python Programming
Kamal Acharya
 
PPTX
Chapter7-Introduction to Python.pptx
lemonchoos
 
PPTX
introduction to python
Jincy Nelson
 
PPTX
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
PPTX
AI_2nd Lab.pptx
MohammedAlYemeni1
 
PPT
Python first day
farkhand
 
PPT
Python first day
MARISSTELLA2
 
2. Values and Data types in Python.pptx
deivanayagamramachan
 
1. python programming
sreeLekha51
 
Introduction to python
Ayshwarya Baburam
 
"Automata Basics and Python Applications"
ayeshasiraj34
 
Python Tutorial Part 1
Haitham El-Ghareeb
 
python presentation.pptx
NightTune44
 
Python unit 2 is added. Has python related programming content
swarna16
 
Python-Basics.pptx
TamalSengupta8
 
Introduction to Python Programming for beginners
MuhammadUsman406079
 
Engineering CS 5th Sem Python Module -2.pptx
hardii0991
 
introduction to python,datatypes,operators
MrANaveenKumar
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
 
PYTHON PPT.pptx python is very useful for day to day life
NaitikSingh33
 
Fundamentals of Python Programming
Kamal Acharya
 
Chapter7-Introduction to Python.pptx
lemonchoos
 
introduction to python
Jincy Nelson
 
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
AI_2nd Lab.pptx
MohammedAlYemeni1
 
Python first day
farkhand
 
Python first day
MARISSTELLA2
 
Ad

More from Akhil Kaushik (20)

PPT
Symbol Table, Error Handler & Code Generation
Akhil Kaushik
 
PPTX
Code Optimization
Akhil Kaushik
 
PPTX
Parsing in Compiler Design
Akhil Kaushik
 
PPTX
Context Free Grammar
Akhil Kaushik
 
PPTX
Error Detection & Recovery
Akhil Kaushik
 
PPTX
Symbol Table
Akhil Kaushik
 
PPTX
Lexical Analyzer Implementation
Akhil Kaushik
 
PPTX
NFA & DFA
Akhil Kaushik
 
PPTX
Lexical Analysis - Compiler Design
Akhil Kaushik
 
PPTX
File Handling Python
Akhil Kaushik
 
PPTX
Regular Expressions
Akhil Kaushik
 
PPTX
Algorithms & Complexity Calculation
Akhil Kaushik
 
PPTX
Intro to Data Structure & Algorithms
Akhil Kaushik
 
PPTX
Decision Making & Loops
Akhil Kaushik
 
PPTX
Basic programs in Python
Akhil Kaushik
 
PPTX
Introduction to Python Programming
Akhil Kaushik
 
PPT
Compiler Design Basics
Akhil Kaushik
 
PPTX
Bootstrapping in Compiler
Akhil Kaushik
 
PPTX
Compiler construction tools
Akhil Kaushik
 
PPTX
Phases of compiler
Akhil Kaushik
 
Symbol Table, Error Handler & Code Generation
Akhil Kaushik
 
Code Optimization
Akhil Kaushik
 
Parsing in Compiler Design
Akhil Kaushik
 
Context Free Grammar
Akhil Kaushik
 
Error Detection & Recovery
Akhil Kaushik
 
Symbol Table
Akhil Kaushik
 
Lexical Analyzer Implementation
Akhil Kaushik
 
NFA & DFA
Akhil Kaushik
 
Lexical Analysis - Compiler Design
Akhil Kaushik
 
File Handling Python
Akhil Kaushik
 
Regular Expressions
Akhil Kaushik
 
Algorithms & Complexity Calculation
Akhil Kaushik
 
Intro to Data Structure & Algorithms
Akhil Kaushik
 
Decision Making & Loops
Akhil Kaushik
 
Basic programs in Python
Akhil Kaushik
 
Introduction to Python Programming
Akhil Kaushik
 
Compiler Design Basics
Akhil Kaushik
 
Bootstrapping in Compiler
Akhil Kaushik
 
Compiler construction tools
Akhil Kaushik
 
Phases of compiler
Akhil Kaushik
 
Ad

Recently uploaded (20)

PPTX
The Future of Artificial Intelligence Opportunities and Risks Ahead
vaghelajayendra784
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PPTX
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Digital Professionalism and Interpersonal Competence
rutvikgediya1
 
PPTX
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
PPTX
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
PPTX
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
PDF
EXCRETION-STRUCTURE OF NEPHRON,URINE FORMATION
raviralanaresh2
 
PPTX
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
PPT
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PPTX
K-Circle-Weekly-Quiz12121212-May2025.pptx
Pankaj Rodey
 
PPTX
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
PPTX
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
PDF
John Keats introduction and list of his important works
vatsalacpr
 
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
The Future of Artificial Intelligence Opportunities and Risks Ahead
vaghelajayendra784
 
Basics and rules of probability with real-life uses
ravatkaran694
 
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
Digital Professionalism and Interpersonal Competence
rutvikgediya1
 
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
EXCRETION-STRUCTURE OF NEPHRON,URINE FORMATION
raviralanaresh2
 
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
K-Circle-Weekly-Quiz12121212-May2025.pptx
Pankaj Rodey
 
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
John Keats introduction and list of his important works
vatsalacpr
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 

Python Data-Types

  • 1. Akhil Kaushik Asstt. Prof., CE Deptt., TIT Bhiwani Data Types in Python
  • 2. Python Introduction • Python is a dynamic-typed language (uses interpreter). • Many other languages are static typed, such as C/C++ and Java (use compiler). • A static typed language requires the programmer to explicitly tell the computer what type of “thing” each data value is.
  • 3. Python Introduction • In Python, you simply give your variables names and assign values to them. • The interpreter takes care of keeping track of what kinds of objects your program is using. • This also means that you can change the size of the values as you develop the program.
  • 4. Names and Tokens • Identifiers can be of unlimited length. • Names and identifiers are case sensitive. • Allowed characters: a-z, A-Z, 0-9 & underscore. • It must begin with a letter or underscore. • Names/variables in Python do not have a type. Values have types.
  • 5. Names and Tokens • Naming conventions Not rigid, but: –Modules and packages - all lower case. –Global and constants – Upper case. –Classes - caps with initial upper. –Methods and functions – All lower case with words separated by underscores. –Local variables - Lowercase (with underscore between words) or bumpy caps with initial lower or your choice.
  • 6. Blocks and Indentation • Python represents block structure and nested block structure with indentation, not with begin and end brackets. • Indentation is 4 spaces and no hard tabs. • Reduces clutter. Eliminates all the curly brackets.
  • 7. Modules & Packages • Modules correspond to files with a "*.py" extension. • Packages correspond to a directory (or folder) in the file system; a package contains a file named "__init__.py". Both modules and packages can be imported. • Packages - A directory containing a file named "__init__.py".
  • 8. Operators • Python defines the following operators: • The comparison operators <> and != are alternate spellings of the same operator. • Logical Operators: and, or, not, is, in
  • 9. Operators’ Precedence • Table summarizes the operator precedence in Python, from lowest precedence to highest precedence. • Operators on the same line have the same precedence. • At end, +,-,*, / come.
  • 10. Data Types • Numeric Types • Strings • Lists • Tuples • Dictionaries • Sets • Files, Boolean, etc.
  • 11. Data Types - Numeric • Python supports 2 types of numbers: – Integer Ex: myint = 7 print(myint) – Float Ex: myfnt = 7.0 print(myfnt) myff = float(28) print(myff) – complex nos: 3.14j
  • 12. Data Types - Strings • Strings in Python are identified as a contiguous set of characters represented in the quotation marks. • Python allows either pair of single or double quotes. • Advantage of using double quotes is that we don’t need to worry about apostrophes. • More than 1 variable can be assigned values simultaneously.
  • 13. Data Types - Strings Ex: mys = ‘Hello’ print(mys) myss = “Mate” print(myss) print(mys + “ ”+myss)
  • 14. Data Types - Strings • Subsets of strings can be taken using the slice operator ([ ] and [:] ) with indexes starting at 0 in the beginning of the string and working their way from - 1 to the end. • The plus (+) sign is the string concatenation operator and the asterisk (*) is the repetition operator.
  • 15. Data Types - Strings
  • 16. Data Types - Strings
  • 17. Data Types – Formatted Strings f-strings are string literals that have an ‘f’ at the beginning and curly braces containing expressions that will be replaced with their values.
  • 18. Data Types - Lists • It is like a structure that may contain different types of data elements. • Ex: list1 = [2233, 88.76, 45+6j, “wfh”, 56] • Ex: list1[2] = “new”
  • 19. Data Types - Lists The concept of slicing can also be applied here:
  • 20. Data Types - Lists
  • 21. Data Types - Tuples • It is similar to lists, but once created it cannot be edited. • Tuple uses parenthesis () instead of square brackets[].
  • 22. Data Types - Dictionary • It is an alternate to the switch-case construct and is used as a key-value pair. • Each key is separated from its value by a colon (:), the items are separated by commas, and the whole thing is enclosed in curly braces. • An empty dictionary without any items is written with just two curly braces, like this: {}.
  • 23. Data Types - Dictionary
  • 24. Data Types – Boolean • Boolean type provides two built-in values: – True and False. • It denotes by the class bool. • True can be represented by any non-zero value or 'T' whereas false can be represented by the 0 or 'F'. • Ex: print(type(True)) • Ex: print(type(False))
  • 25. Data Types - Sets • Python Set is the unordered collection of the data type. • It is iteratable, mutable(can modify after creation), and has unique elements. • In set, the order of the elements is undefined. • The set is created by using a built-in function set(), or a sequence of elements is passed in the curly braces and separated by the comma.
  • 26. Data Types - Sets Ex: a = {5,2,3,1,4} # printing set variable print("a = ", a) # data type of variable a print(type(a))
  • 27. Data Types - Sets Ex: set1 = set() set2 = {'James', 2, 3,'Pyt'} print(set2) set2.add(10) print(set2) set2.remove(2) print(set2)