SlideShare a Scribd company logo
2
Most read
8
Most read
10
Most read
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

PDF
Data types in python
PDF
Function in Python
PDF
PPTX
Python array
PPT
pointers
PPTX
Operators in python
PDF
Python Variable Types, List, Tuple, Dictionary
Data types in python
Function in Python
Python array
pointers
Operators in python
Python Variable Types, List, Tuple, Dictionary

What's hot (20)

PDF
Python Function.pdf
PPTX
Python dictionary
PPTX
Print input-presentation
PPTX
Introduction to Python programming
PPTX
constructors in java ppt
PPTX
Functions in python
PPTX
Chapter 15 Lists
PPT
Strings
PPTX
Constructor in java
PPT
Python List.ppt
PPTX
Python datetime
PPTX
2- Dimensional Arrays
PPTX
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
PPTX
Pointers in c language
DOCX
Data Structure Project File
PPTX
Python dictionary
PDF
Teach your kids how to program with Python and the Raspberry Pi
PPTX
Python: Modules and Packages
PPTX
Python list
Python Function.pdf
Python dictionary
Print input-presentation
Introduction to Python programming
constructors in java ppt
Functions in python
Chapter 15 Lists
Strings
Constructor in java
Python List.ppt
Python datetime
2- Dimensional Arrays
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
Pointers in c language
Data Structure Project File
Python dictionary
Teach your kids how to program with Python and the Raspberry Pi
Python: Modules and Packages
Python list
Ad

Similar to Python standard data types (20)

PPTX
Python- Basic. pptx with lists, tuples dictionaries and data types
PPTX
Python- Basic.pptx with data types, lists, and tuples with dictionary
ODP
Python slide.1
PPTX
1. python programming
PPTX
Data Types in Python programming and its usefulness
DOCX
unit 1.docx
PPTX
Datatypes.pptx
PDF
Datatypes in Python.pdf
PPTX
Python data type
PPTX
pythondatatypes.pptx
PPTX
Python data type
PDF
Python Data Types (1).pdf
PDF
Python Data Types.pdf
PDF
13- Data and Its Types presentation kafss
PPTX
Chapter 2-Programming Basics and Arrays.pptx Chapter 2-Programming Basics and...
PDF
Basics of Python and Numpy_583aab2b47e30ad9647bc4aaf13b884d.pdf
PPTX
PPTX
Python_IoT.pptx
PPTX
DATA, EXPRESSIONS, STATEMENTS IN PYTHON PROGRAMMING
PDF
Datatypes in python
Python- Basic. pptx with lists, tuples dictionaries and data types
Python- Basic.pptx with data types, lists, and tuples with dictionary
Python slide.1
1. python programming
Data Types in Python programming and its usefulness
unit 1.docx
Datatypes.pptx
Datatypes in Python.pdf
Python data type
pythondatatypes.pptx
Python data type
Python Data Types (1).pdf
Python Data Types.pdf
13- Data and Its Types presentation kafss
Chapter 2-Programming Basics and Arrays.pptx Chapter 2-Programming Basics and...
Basics of Python and Numpy_583aab2b47e30ad9647bc4aaf13b884d.pdf
Python_IoT.pptx
DATA, EXPRESSIONS, STATEMENTS IN PYTHON PROGRAMMING
Datatypes in python
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)

PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Insiders guide to clinical Medicine.pdf
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PPTX
Onica Farming 24rsclub profitable farm business
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Pharma ospi slides which help in ospi learning
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
NOI Hackathon - Summer Edition - GreenThumber.pptx
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Insiders guide to clinical Medicine.pdf
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
Open Quiz Monsoon Mind Game Final Set.pptx
Week 4 Term 3 Study Techniques revisited.pptx
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
Anesthesia in Laparoscopic Surgery in India
Open Quiz Monsoon Mind Game Prelims.pptx
Onica Farming 24rsclub profitable farm business
Pharmacology of Heart Failure /Pharmacotherapy of CHF
The Final Stretch: How to Release a Game and Not Die in the Process.
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Renaissance Architecture: A Journey from Faith to Humanism
Pharma ospi slides which help in ospi learning
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
3rd Neelam Sanjeevareddy Memorial Lecture.pdf

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