SlideShare uma empresa Scribd logo
1 de 28
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 !!!

Mais conteúdo relacionado

Mais procurados

Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptxAkshayAggarwal79
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionarynitamhaske
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programmingSrinivas Narasegouda
 
Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialQA TrainingHub
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in pythonTMARAGATHAM
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and commentsNilimesh Halder
 
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYAChapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYAMaulik Borsaniya
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide shareDevashish Kumar
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python amiable_indian
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data typesMohd Sajjad
 
File Handling Python
File Handling PythonFile Handling Python
File Handling PythonAkhil Kaushik
 

Mais procurados (20)

Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python Tutorial
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
 
Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and comments
 
Python
PythonPython
Python
 
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYAChapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
Python list
Python listPython list
Python list
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
 
Python ppt
Python pptPython ppt
Python ppt
 
File Handling Python
File Handling PythonFile Handling Python
File Handling Python
 
Python ppt
Python pptPython ppt
Python ppt
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 

Semelhante a Python Data-Types

2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptx2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptxdeivanayagamramachan
 
1. python programming
1. python programming1. python programming
1. python programmingsreeLekha51
 
python presentation.pptx
python presentation.pptxpython presentation.pptx
python presentation.pptxNightTune44
 
Engineering CS 5th Sem Python Module -2.pptx
Engineering CS 5th Sem Python Module -2.pptxEngineering CS 5th Sem Python Module -2.pptx
Engineering CS 5th Sem Python Module -2.pptxhardii0991
 
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.pptxsangeeta borde
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python ProgrammingKamal Acharya
 
Chapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptxChapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptxlemonchoos
 
introduction to python
 introduction to python introduction to python
introduction to pythonJincy Nelson
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxNimrahafzal1
 
Python first day
Python first dayPython first day
Python first dayfarkhand
 
Programming Basics.pptx
Programming Basics.pptxProgramming Basics.pptx
Programming Basics.pptxmahendranaik18
 
Learn Python The Hard Way Presentation
Learn Python The Hard Way PresentationLearn Python The Hard Way Presentation
Learn Python The Hard Way PresentationAmira ElSharkawy
 

Semelhante a Python Data-Types (20)

2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptx2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptx
 
1. python programming
1. python programming1. python programming
1. python programming
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
 
python presentation.pptx
python presentation.pptxpython presentation.pptx
python presentation.pptx
 
Python-Basics.pptx
Python-Basics.pptxPython-Basics.pptx
Python-Basics.pptx
 
Engineering CS 5th Sem Python Module -2.pptx
Engineering CS 5th Sem Python Module -2.pptxEngineering CS 5th Sem Python Module -2.pptx
Engineering CS 5th Sem Python Module -2.pptx
 
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
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python Programming
 
Chapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptxChapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptx
 
introduction to python
 introduction to python introduction to python
introduction to python
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
 
AI_2nd Lab.pptx
AI_2nd Lab.pptxAI_2nd Lab.pptx
AI_2nd Lab.pptx
 
Python first day
Python first dayPython first day
Python first day
 
Python first day
Python first dayPython first day
Python first day
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
Programming Basics.pptx
Programming Basics.pptxProgramming Basics.pptx
Programming Basics.pptx
 
pythondatatypes.pptx
pythondatatypes.pptxpythondatatypes.pptx
pythondatatypes.pptx
 
Python Programming 1.pptx
Python Programming 1.pptxPython Programming 1.pptx
Python Programming 1.pptx
 
Learn Python The Hard Way Presentation
Learn Python The Hard Way PresentationLearn Python The Hard Way Presentation
Learn Python The Hard Way Presentation
 
Variables&DataTypes.pptx
Variables&DataTypes.pptxVariables&DataTypes.pptx
Variables&DataTypes.pptx
 

Mais de Akhil Kaushik

Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationAkhil Kaushik
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler DesignAkhil Kaushik
 
Context Free Grammar
Context Free GrammarContext Free Grammar
Context Free GrammarAkhil Kaushik
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & RecoveryAkhil Kaushik
 
Lexical Analyzer Implementation
Lexical Analyzer ImplementationLexical Analyzer Implementation
Lexical Analyzer ImplementationAkhil Kaushik
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignAkhil Kaushik
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity CalculationAkhil Kaushik
 
Intro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsIntro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsAkhil Kaushik
 
Decision Making & Loops
Decision Making & LoopsDecision Making & Loops
Decision Making & LoopsAkhil Kaushik
 
Basic programs in Python
Basic programs in PythonBasic programs in Python
Basic programs in PythonAkhil Kaushik
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python ProgrammingAkhil Kaushik
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil Kaushik
 
Bootstrapping in Compiler
Bootstrapping in CompilerBootstrapping in Compiler
Bootstrapping in CompilerAkhil Kaushik
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction toolsAkhil Kaushik
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to CompilersAkhil Kaushik
 

Mais de Akhil Kaushik (20)

Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Context Free Grammar
Context Free GrammarContext Free Grammar
Context Free Grammar
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
 
Symbol Table
Symbol TableSymbol Table
Symbol Table
 
Lexical Analyzer Implementation
Lexical Analyzer ImplementationLexical Analyzer Implementation
Lexical Analyzer Implementation
 
NFA & DFA
NFA & DFANFA & DFA
NFA & DFA
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity Calculation
 
Intro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsIntro to Data Structure & Algorithms
Intro to Data Structure & Algorithms
 
Decision Making & Loops
Decision Making & LoopsDecision Making & Loops
Decision Making & Loops
 
Basic programs in Python
Basic programs in PythonBasic programs in Python
Basic programs in Python
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Bootstrapping in Compiler
Bootstrapping in CompilerBootstrapping in Compiler
Bootstrapping in Compiler
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction tools
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 

Último

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 

Último (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 

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)
  • 28. Akhil Kaushik akhilkaushik05@gmail.com 9416910303 CONTACT ME AT: Akhil Kaushik akhilkaushik05@gmail.com 9416910303 THANK YOU !!!