SlideShare a Scribd company logo
2
Most read
7
Most read
9
Most read
Values and Data types
in Python
Prepared By,
P.Jothi Thilaga, AP/CSE
Ramco Institute of Technology
Rajapalayam
Value
one of the fundamental things, like a number, a
character or a string that program manipulates.
Example: a = 25, b= “Hi”
25, Hi represents values
Data type
refers to the type and size of data. Variables can
hold values of different data types. Python is a
purely object oriented language. It refers to
everything as an object, including numbers and
strings.
The five standard data types supported by python
includes:
Number
String
List
Tuple
Dictionary
Numbers
Number refers to a numeric value.
It includes
 integers
 long integers
 floating point
 complex numbers
Integers are whole numbers with no fractional parts.
They can be either positive, negative or zero value.
Long integers in python is displayed with an
uppercase L (56788333354533L is a long integer). -
supported only in python 2 version not in python 3.
Floating point numbers are numbers with fractions
or decimal points. Floating point values can be
expressed in scientific notation using the letter ‘e’ or
‘E’.
Complex number is a number that can be expressed
in the form a + bi, where a and b are real numbers,
and i is the imaginary unit.
Boolean is another data type in Python.
A variable of Boolean type can have one of
the two values - True or False.
The type() function can be used to know which data
type a variable or a value belongs to.
The isinstance() function to check if an object
belongs to a particular class.
Examples:
a = 5
print(a, "is of type", type(a))
a = 2.0
print(a, "is of type", type(a))
a = 1+2j
print(a, "is complex no.?", isinstance(1+2j,complex))
Output:
5 is of type <class 'int'>
2.0 is of type <class 'float'>
(1+2j) is complex no.? True
List
List is an ordered sequence of items. It is one
of the most used data type in Python and is
very flexible.
All the items in a list do not need to be of the
same type.
Lists are mutable. The elements in the list can
be modified.
To declare a list in python, separate the items
using commas and enclose them within square
brackets [ ].
>>> a = [1, 2.2, 'python'] The slicing operator [ ] is used
to extract an item or a range of items from a list. Index
starts from 0 in Python.
Examples:
>>>a = [5,10,15,20,25,30,35,40]
>>>a[2]
15
>>>print("a[0:3] = ", a[0:3])
a[0:3] = [5, 10, 15]
Tuple
Tuple is an ordered sequence of items same as
list. The only difference is that tuples are
immutable. Tuples once created cannot be
modified.
It is defined within parentheses ( ) where items
are separated by commas.
Example:
>>> t = (5, 'program', 1+3j, 4, 11.5)
print("t[1] = ", t[1])
print("t[0:3] = ", t[0:3])
Output:
t[1] = program
t[0:3] = (5, 'program', (1+3j))
Strings
A String in python can be a series or a
sequence of alphabets, numerals and special
characters.
Single quotes or double quotes are used to
represent strings.
>>> s = "This is a string"
Strings are immutable.
Examples:
s = 'Hello world!'
print("s[4] = ", s[4])
print("s[6:11] = ", s[6:11])
Output:
s[4] = o
s[6:11] = world
Dictionary
A python dictionary is an unordered collection
of key-value pairs.
Keys and values can be of any type in a
dictionary.
Items in dictionary are separated by comma
and enclosed with the curly-braces { }.
Example:
>>>dict={1:“hi”,2: “hello”}
Exercises
1. --------- are the reserved memory locations that stores
values.
2. What data type is used to store values in terms of key
and value?
(a) list
(b) tuple
(c) class
(d) dictionary
3. What data type is the object below ?
L = [1.0, 15, ‘hi’, 27]
(a) list
(b) dictionary
(c) array
(d) tuple
Answers
1. Variables
2. (d) dictionary
3. (a) list
Thank You

More Related Content

PPTX
Python - Data Structures
PDF
Introduction to Python
PDF
Strings in Python
PPTX
PDF
Python-03| Data types
PPTX
Python Course for Beginners
PDF
Python Sequence Data types in Brief
PPTX
USER DEFINE FUNCTIONS IN PYTHON
Python - Data Structures
Introduction to Python
Strings in Python
Python-03| Data types
Python Course for Beginners
Python Sequence Data types in Brief
USER DEFINE FUNCTIONS IN PYTHON

What's hot (20)

PPTX
Python strings presentation
PPTX
Data types in python
PPTX
Variables in python
PPTX
File Handling Python
PDF
Python libraries
PPT
Python GUI Programming
PDF
Lesson 02 python keywords and identifiers
PPTX
Functions in Python
PPSX
Modules and packages in python
PDF
Python programming : Files
PPTX
Python ppt
PDF
Datatypes in python
PPTX
Chapter 05 classes and objects
PDF
Arrays In Python | Python Array Operations | Edureka
PDF
Python programming : Standard Input and Output
PPT
Input and output in C++
PDF
Python programming : Classes objects
PDF
Python recursion
Python strings presentation
Data types in python
Variables in python
File Handling Python
Python libraries
Python GUI Programming
Lesson 02 python keywords and identifiers
Functions in Python
Modules and packages in python
Python programming : Files
Python ppt
Datatypes in python
Chapter 05 classes and objects
Arrays In Python | Python Array Operations | Edureka
Python programming : Standard Input and Output
Input and output in C++
Python programming : Classes objects
Python recursion
Ad

Similar to Values and Data types in python (20)

PPTX
2. Values and Data types in Python.pptx
PPTX
Data Types In Python.pptx
PPTX
Python variables and data types.pptx
DOCX
unit 1.docx
PPTX
IOT notes,................................
PPTX
Python data type
PPTX
PPTX
Python Data-Types
PDF
Programming in Civil Engineering_UNIT 2_NOTES
PDF
4. Data Handling computer shcience pdf s
PPTX
introduction to python,datatypes,operators
PPTX
Basic data types in python
PDF
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
PPTX
009 Data Handling class 11 -converted.pptx
PDF
Datatypes in Python.pdf
PDF
E-Notes_3720_Content_Document_20250107032323PM.pdf
PPT
Python - Module 1.ppt
PPTX
Cthhis_is_cybersecurty_and_cyber_sxec.pptx
PPTX
Chapter - 2.pptx
PPTX
009 Data Handling .pptx
2. Values and Data types in Python.pptx
Data Types In Python.pptx
Python variables and data types.pptx
unit 1.docx
IOT notes,................................
Python data type
Python Data-Types
Programming in Civil Engineering_UNIT 2_NOTES
4. Data Handling computer shcience pdf s
introduction to python,datatypes,operators
Basic data types in python
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
009 Data Handling class 11 -converted.pptx
Datatypes in Python.pdf
E-Notes_3720_Content_Document_20250107032323PM.pdf
Python - Module 1.ppt
Cthhis_is_cybersecurty_and_cyber_sxec.pptx
Chapter - 2.pptx
009 Data Handling .pptx
Ad

Recently uploaded (20)

PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PPTX
Road Safety tips for School Kids by a k maurya.pptx
PPTX
Internship_Presentation_Final engineering.pptx
PPTX
Soil science - sampling procedures for soil science lab
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
PDF
Top 10 read articles In Managing Information Technology.pdf
PPT
SCOPE_~1- technology of green house and poyhouse
PDF
classification of cubic lattice structure
PDF
International Journal of Information Technology Convergence and Services (IJI...
PDF
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
PDF
Queuing formulas to evaluate throughputs and servers
PPT
Chapter 6 Design in software Engineeing.ppt
PPTX
metal cuttingmechancial metalcutting.pptx
PDF
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
PDF
ETO & MEO Certificate of Competency Questions and Answers
PDF
flutter Launcher Icons, Splash Screens & Fonts
PPTX
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
PPTX
TE-AI-Unit VI notes using planning model
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Road Safety tips for School Kids by a k maurya.pptx
Internship_Presentation_Final engineering.pptx
Soil science - sampling procedures for soil science lab
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Structs to JSON How Go Powers REST APIs.pdf
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
Top 10 read articles In Managing Information Technology.pdf
SCOPE_~1- technology of green house and poyhouse
classification of cubic lattice structure
International Journal of Information Technology Convergence and Services (IJI...
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
Queuing formulas to evaluate throughputs and servers
Chapter 6 Design in software Engineeing.ppt
metal cuttingmechancial metalcutting.pptx
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
ETO & MEO Certificate of Competency Questions and Answers
flutter Launcher Icons, Splash Screens & Fonts
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
TE-AI-Unit VI notes using planning model

Values and Data types in python

  • 1. Values and Data types in Python Prepared By, P.Jothi Thilaga, AP/CSE Ramco Institute of Technology Rajapalayam
  • 2. Value one of the fundamental things, like a number, a character or a string that program manipulates. Example: a = 25, b= “Hi” 25, Hi represents values Data type refers to the type and size of data. Variables can hold values of different data types. Python is a purely object oriented language. It refers to everything as an object, including numbers and strings.
  • 3. The five standard data types supported by python includes: Number String List Tuple Dictionary
  • 4. Numbers Number refers to a numeric value. It includes  integers  long integers  floating point  complex numbers
  • 5. Integers are whole numbers with no fractional parts. They can be either positive, negative or zero value. Long integers in python is displayed with an uppercase L (56788333354533L is a long integer). - supported only in python 2 version not in python 3. Floating point numbers are numbers with fractions or decimal points. Floating point values can be expressed in scientific notation using the letter ‘e’ or ‘E’. Complex number is a number that can be expressed in the form a + bi, where a and b are real numbers, and i is the imaginary unit.
  • 6. Boolean is another data type in Python. A variable of Boolean type can have one of the two values - True or False. The type() function can be used to know which data type a variable or a value belongs to. The isinstance() function to check if an object belongs to a particular class.
  • 7. Examples: a = 5 print(a, "is of type", type(a)) a = 2.0 print(a, "is of type", type(a)) a = 1+2j print(a, "is complex no.?", isinstance(1+2j,complex)) Output: 5 is of type <class 'int'> 2.0 is of type <class 'float'> (1+2j) is complex no.? True
  • 8. List List is an ordered sequence of items. It is one of the most used data type in Python and is very flexible. All the items in a list do not need to be of the same type. Lists are mutable. The elements in the list can be modified. To declare a list in python, separate the items using commas and enclose them within square brackets [ ].
  • 9. >>> a = [1, 2.2, 'python'] The slicing operator [ ] is used to extract an item or a range of items from a list. Index starts from 0 in Python. Examples: >>>a = [5,10,15,20,25,30,35,40] >>>a[2] 15 >>>print("a[0:3] = ", a[0:3]) a[0:3] = [5, 10, 15]
  • 10. Tuple Tuple is an ordered sequence of items same as list. The only difference is that tuples are immutable. Tuples once created cannot be modified. It is defined within parentheses ( ) where items are separated by commas.
  • 11. Example: >>> t = (5, 'program', 1+3j, 4, 11.5) print("t[1] = ", t[1]) print("t[0:3] = ", t[0:3]) Output: t[1] = program t[0:3] = (5, 'program', (1+3j))
  • 12. Strings A String in python can be a series or a sequence of alphabets, numerals and special characters. Single quotes or double quotes are used to represent strings. >>> s = "This is a string" Strings are immutable.
  • 13. Examples: s = 'Hello world!' print("s[4] = ", s[4]) print("s[6:11] = ", s[6:11]) Output: s[4] = o s[6:11] = world
  • 14. Dictionary A python dictionary is an unordered collection of key-value pairs. Keys and values can be of any type in a dictionary. Items in dictionary are separated by comma and enclosed with the curly-braces { }. Example: >>>dict={1:“hi”,2: “hello”}
  • 15. Exercises 1. --------- are the reserved memory locations that stores values. 2. What data type is used to store values in terms of key and value? (a) list (b) tuple (c) class (d) dictionary 3. What data type is the object below ? L = [1.0, 15, ‘hi’, 27] (a) list (b) dictionary (c) array (d) tuple
  • 16. Answers 1. Variables 2. (d) dictionary 3. (a) list