SlideShare a Scribd company logo
Swipe
Python Standard Data Types
Data types are the classification or categorization
of data items.
It represents the kind of value that tells what
operations can be performed on a particular data.
Since everything is an object in Python
programming, data types are actually classes and
variables are instance (object) of these classes.
Standard Data Types
Numbers
String
List
Tuple
Dictionary
Types of standard data types
Python Numbers
Number data types store numeric values. Number
objects are created when you assign a value to
them.
For example −
var1 = 1
var2 = 10
You can also delete the reference to a number
object by using the del statement. The syntax of
the del statement is :-
del var1[,var2[,var3[....,varN]]]]
You can delete a single object or multiple objects
by using the del statement.
For example
del var
del var_a, var_b
Python Strings
Strings in Python are identified as a contiguous set of
characters represented in the quotation marks.
Python allows for either pairs of single or double
quotes. 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
at the end.
#!/usr/bin/python
str = 'Hello World!'
print str # Prints complete string
print str[0] # Prints first character of the string
print str[2:5] # Prints characters starting from 3rd to 5th
print str[2:] # Prints string starting from 3rd character
print str * 2 # Prints string two times
print str + "TEST" # Prints concatenated string
The plus (+) sign is the string concatenation
operator and the asterisk (*) is the repetition
operator.
For example
This will produce the following result
Hello World!
H
llo
llo World!
Hello World!Hello World!
Hello World!TEST
Python Lists
Lists are the most versatile of Python's compound
data types. A list contains items separated by
commas and enclosed within square brackets ([]).
To some extent, lists are similar to arrays in C.
One difference between them is that all the items
belonging to a list can be of different data type.
The values stored in a list can be accessed using
the slice operator ([ ] and [:]) with indexes starting
at 0 in the beginning of the list and working their
way to end -1.
The plus (+) sign is the list concatenation operator,
and the asterisk (*) is the repetition operator.
For example
#!/usr/bin/python
list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]
tinylist = [123, 'john']
print list # Prints complete list
print list[0] # Prints first element of the list
print list[1:3] # Prints elements starting from 2nd till 3rd
print list[2:] # Prints elements starting from 3rd element
print tinylist * 2 # Prints list two times
print list + tinylist # Prints concatenated lists
This produce the following result
['abcd', 786, 2.23, 'john', 70.2]
abcd
[786, 2.23]
[2.23, 'john', 70.2]
[123, 'john', 123, 'john']
['abcd', 786, 2.23, 'john', 70.2, 123, 'john']
Python Tuples
A tuple is another sequence data type that is
similar to the list. A tuple consists of a number of
values separated by commas.
Unlike lists, however, tuples are enclosed within
parentheses.
The main differences between lists and tuples are:
Lists are enclosed in brackets ( [ ] ) and their
elements and size can be changed, while tuples
are enclosed in parentheses ( ( ) ) and cannot be
updated.
Tuples can be thought of as read-only lists.
For example
#!/usr/bin/python
tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 )
tinytuple = (123, 'john')
print tuple # Prints the complete tuple
print tuple[0] # Prints first element of the tuple
print tuple[1:3] # Prints elements of the tuple starting from
2nd till 3rd
print tuple[2:] # Prints elements of the tuple starting from
3rd element
print tinytuple * 2 # Prints the contents of the tuple twice
print tuple + tinytuple # Prints concatenated tuples
This produce the following result
('abcd', 786, 2.23, 'john', 70.2)
abcd
(786, 2.23)
(2.23, 'john', 70.2)
(123, 'john', 123, 'john')
('abcd', 786, 2.23, 'john', 70.2, 123, 'john')
Python Dictionary
Python's dictionaries are kind of hash table type.
They work like associative arrays or hashes found
in Perl and consist of key-value pairs.
A dictionary key can be almost any Python type,
but are usually numbers or strings.
Values, on the other hand, can be any arbitrary
Python object.
Dictionaries are enclosed by curly braces ({ }) and
values can be assigned and accessed using square
braces ([]).
For example
#!/usr/bin/python
dict = {}
dict['one'] = "This is one"
dict[2] = "This is two"
tinydict = {'name': 'john','code':6734, 'dept': 'sales'}
print dict['one'] # Prints value for 'one' key
print dict[2] # Prints value for 2 key
print tinydict # Prints complete dictionary
print tinydict.keys() # Prints all the keys
print tinydict.values() # Prints all the values
This produce the following result
This is one
This is two
{'dept': 'sales', 'code': 6734, 'name': 'john'}
['dept', 'code', 'name']
['sales', 6734, 'john']
Python Operations
Python - Decision Making
Python - Functions
Stay Tuned with
Topics for next Post

More Related Content

PPTX
Standard data-types-in-py
ODP
Python básico
PDF
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PPTX
Tuple in python
PPTX
Chapter 06 constructors and destructors
PDF
How to use Map() Filter() and Reduce() functions in Python | Edureka
PPTX
Python dictionary
DOCX
áRbol binario
Standard data-types-in-py
Python básico
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
Tuple in python
Chapter 06 constructors and destructors
How to use Map() Filter() and Reduce() functions in Python | Edureka
Python dictionary
áRbol binario

What's hot (20)

PDF
Lesson 02 python keywords and identifiers
PPTX
Templates in c++
PDF
Overview of python 2019
PPTX
Strings in Python
PDF
Programming in Java: Arrays
PPTX
List in python
PPTX
Database connectivity in python
PPTX
Presentation on python data type
PPTX
PPTX
Manipulators in c++
PDF
Python Programming - VI. Classes and Objects
PPT
Introduction to method overloading & method overriding in java hdm
PDF
Strings in Python
PPTX
C vs c++
PDF
Python revision tour II
PPTX
class and objects
PDF
Java quick reference
PDF
Python Data Types.pdf
Lesson 02 python keywords and identifiers
Templates in c++
Overview of python 2019
Strings in Python
Programming in Java: Arrays
List in python
Database connectivity in python
Presentation on python data type
Manipulators in c++
Python Programming - VI. Classes and Objects
Introduction to method overloading & method overriding in java hdm
Strings in Python
C vs c++
Python revision tour II
class and objects
Java quick reference
Python Data Types.pdf
Ad

Similar to Python standard data types (20)

PPTX
Python data type
PDF
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
DOCX
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
PPTX
Python Course for Beginners
ODP
Python slide.1
PPTX
Python Session - 3
PPTX
1. python programming
PPTX
introduction to python programming concepts
DOCX
unit 1.docx
PDF
Unit 1-Part-4-Lists, tuples and dictionaries.pdf
PPTX
Data types in python
PPTX
List_tuple_dictionary.pptxList_tuple_dictionary.pptx
PPTX
Python list tuple dictionary presentation
PDF
Datatypes in Python.pdf
PPTX
Python Datatypes by SujithKumar
PPTX
1-Introduction to Python, features of python, history of python(1).pptx
PDF
updated_tuple_in_python.pdf
PPTX
List_tuple_dictionary.pptx
PPTX
11 Introduction to lists.pptx
PDF
beginners_python_cheat_sheet -python cheat sheet description
Python data type
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
Python Course for Beginners
Python slide.1
Python Session - 3
1. python programming
introduction to python programming concepts
unit 1.docx
Unit 1-Part-4-Lists, tuples and dictionaries.pdf
Data types in python
List_tuple_dictionary.pptxList_tuple_dictionary.pptx
Python list tuple dictionary presentation
Datatypes in Python.pdf
Python Datatypes by SujithKumar
1-Introduction to Python, features of python, history of python(1).pptx
updated_tuple_in_python.pdf
List_tuple_dictionary.pptx
11 Introduction to lists.pptx
beginners_python_cheat_sheet -python cheat sheet description
Ad

More from Learnbay Datascience (20)

PDF
Top data science projects
PDF
Python my SQL - create table
PDF
Python my SQL - create database
PDF
Python my sql database connection
PDF
Python - mySOL
PDF
AI - Issues and Terminology
PDF
AI - Fuzzy Logic Systems
PDF
AI - working of an ns
PDF
Artificial Intelligence- Neural Networks
PDF
AI - Robotics
PDF
Applications of expert system
PDF
Components of expert systems
PDF
Artificial intelligence - expert systems
PDF
AI - natural language processing
PDF
Ai popular search algorithms
PDF
AI - Agents & Environments
PDF
Artificial intelligence - research areas
PDF
Artificial intelligence composed
PDF
Artificial intelligence intelligent systems
PDF
Applications of ai
Top data science projects
Python my SQL - create table
Python my SQL - create database
Python my sql database connection
Python - mySOL
AI - Issues and Terminology
AI - Fuzzy Logic Systems
AI - working of an ns
Artificial Intelligence- Neural Networks
AI - Robotics
Applications of expert system
Components of expert systems
Artificial intelligence - expert systems
AI - natural language processing
Ai popular search algorithms
AI - Agents & Environments
Artificial intelligence - research areas
Artificial intelligence composed
Artificial intelligence intelligent systems
Applications of ai

Recently uploaded (20)

PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Presentation on HIE in infants and its manifestations
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
master seminar digital applications in india
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Institutional Correction lecture only . . .
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Lesson notes of climatology university.
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Pharma ospi slides which help in ospi learning
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Complications of Minimal Access Surgery at WLH
Presentation on HIE in infants and its manifestations
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Computing-Curriculum for Schools in Ghana
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Microbial disease of the cardiovascular and lymphatic systems
master seminar digital applications in india
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Institutional Correction lecture only . . .
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
human mycosis Human fungal infections are called human mycosis..pptx
A systematic review of self-coping strategies used by university students to ...
Lesson notes of climatology university.
Chinmaya Tiranga quiz Grand Finale.pdf
Anesthesia in Laparoscopic Surgery in India

Python standard data types

  • 2. Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes. Standard Data Types
  • 4. Python Numbers Number data types store numeric values. Number objects are created when you assign a value to them. For example − var1 = 1 var2 = 10 You can also delete the reference to a number object by using the del statement. The syntax of the del statement is :- del var1[,var2[,var3[....,varN]]]] You can delete a single object or multiple objects by using the del statement. For example del var del var_a, var_b
  • 5. Python Strings Strings in Python are identified as a contiguous set of characters represented in the quotation marks. Python allows for either pairs of single or double quotes. 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 at the end.
  • 6. #!/usr/bin/python str = 'Hello World!' print str # Prints complete string print str[0] # Prints first character of the string print str[2:5] # Prints characters starting from 3rd to 5th print str[2:] # Prints string starting from 3rd character print str * 2 # Prints string two times print str + "TEST" # Prints concatenated string The plus (+) sign is the string concatenation operator and the asterisk (*) is the repetition operator. For example
  • 7. This will produce the following result Hello World! H llo llo World! Hello World!Hello World! Hello World!TEST
  • 8. Python Lists Lists are the most versatile of Python's compound data types. A list contains items separated by commas and enclosed within square brackets ([]). To some extent, lists are similar to arrays in C. One difference between them is that all the items belonging to a list can be of different data type. The values stored in a list can be accessed using the slice operator ([ ] and [:]) with indexes starting at 0 in the beginning of the list and working their way to end -1. The plus (+) sign is the list concatenation operator, and the asterisk (*) is the repetition operator.
  • 9. For example #!/usr/bin/python list = [ 'abcd', 786 , 2.23, 'john', 70.2 ] tinylist = [123, 'john'] print list # Prints complete list print list[0] # Prints first element of the list print list[1:3] # Prints elements starting from 2nd till 3rd print list[2:] # Prints elements starting from 3rd element print tinylist * 2 # Prints list two times print list + tinylist # Prints concatenated lists
  • 10. This produce the following result ['abcd', 786, 2.23, 'john', 70.2] abcd [786, 2.23] [2.23, 'john', 70.2] [123, 'john', 123, 'john'] ['abcd', 786, 2.23, 'john', 70.2, 123, 'john']
  • 11. Python Tuples A tuple is another sequence data type that is similar to the list. A tuple consists of a number of values separated by commas. Unlike lists, however, tuples are enclosed within parentheses. The main differences between lists and tuples are: Lists are enclosed in brackets ( [ ] ) and their elements and size can be changed, while tuples are enclosed in parentheses ( ( ) ) and cannot be updated. Tuples can be thought of as read-only lists.
  • 12. For example #!/usr/bin/python tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 ) tinytuple = (123, 'john') print tuple # Prints the complete tuple print tuple[0] # Prints first element of the tuple print tuple[1:3] # Prints elements of the tuple starting from 2nd till 3rd print tuple[2:] # Prints elements of the tuple starting from 3rd element print tinytuple * 2 # Prints the contents of the tuple twice print tuple + tinytuple # Prints concatenated tuples
  • 13. This produce the following result ('abcd', 786, 2.23, 'john', 70.2) abcd (786, 2.23) (2.23, 'john', 70.2) (123, 'john', 123, 'john') ('abcd', 786, 2.23, 'john', 70.2, 123, 'john')
  • 14. Python Dictionary Python's dictionaries are kind of hash table type. They work like associative arrays or hashes found in Perl and consist of key-value pairs. A dictionary key can be almost any Python type, but are usually numbers or strings. Values, on the other hand, can be any arbitrary Python object. Dictionaries are enclosed by curly braces ({ }) and values can be assigned and accessed using square braces ([]).
  • 15. For example #!/usr/bin/python dict = {} dict['one'] = "This is one" dict[2] = "This is two" tinydict = {'name': 'john','code':6734, 'dept': 'sales'} print dict['one'] # Prints value for 'one' key print dict[2] # Prints value for 2 key print tinydict # Prints complete dictionary print tinydict.keys() # Prints all the keys print tinydict.values() # Prints all the values
  • 16. This produce the following result This is one This is two {'dept': 'sales', 'code': 6734, 'name': 'john'} ['dept', 'code', 'name'] ['sales', 6734, 'john']
  • 17. Python Operations Python - Decision Making Python - Functions Stay Tuned with Topics for next Post