SlideShare a Scribd company logo
Values and Data types in Python
Value
• A value is one of the fundamental things, like
a number, a character or a string that program
manipulates.
Example
2,42.0,’Hello,World’ The value belong to
different types.
Literal Constants
 The value of a literal constant can be used directly in programs. For example,
7, 3.9, 'A', and "Hello" are literal constants.
 Numbers refers to a numeric value. You can use four types of numbers in
Python program- integers, long integers, floating point and complex numbers.
 Numbers like 5 or other whole numbers are referred to as integers. Bigger
whole numbers are called long integers. For example, 535633629843L is a
long integer.
 Numbers like are 3.23 and 91.5E-2 are termed as floating point numbers.
 Numbers of a + bi form (like -3 + 7i) are complex numbers.
9/5/2022 Introduction to python 3
Example
9/5/2022 Introduction to python 4
Strings
A string is a group of characters.
• Using Single Quotes ('): For example, a string can be written as 'HELLO'.
• Using Double Quotes ("): Strings in doubles are exactly same as those in
single quotes. Therefore, 'HELLO' is same quoteas "HELLO".
• Using Triple Quotes (''' '''): You can specify multi-line strings using triple
quotes. You can use as many single quotes and double quotes as you
want in a string within triple quotes.
Examples:
• 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 standard data types supported by python
includes:
– Number
– Boolean
– String
– List
– Tuple
– Dictionary
Numbers
• Numbers refers to a numeric value. It includes integers, long
integers, floating point, and complex numbers.
• Integers are whole numbers with no fractional parts. They can be
either positive, negative or zero value. Python displays long
integers with an uppercase L (56788333354533L is a long integer).
• 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’.
• A 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.
• 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.
Example:
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 number?", isinstance(1+2j,complex))
Output:
5 is of type <class 'int'>
2.0 is of type <class 'float'>
(1+2j) is complex number? True
• Boolean is another data type in Python.
• A variable of Boolean type can have one of the
two values- True or False.
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 form 0 in Python.
Example:
>>>a = [5,10,15,20,25,30,35,40]
>>>a[2]
15
>>>print("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)
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.
Example:
s = 'Hello world!'
print("s[4] = ", s[4]) # s[4] = 'o'
print("s[6:11] = ", s[6:11]) # s[6:11] = 'world'
Output:
s[4] = o
s[6:11] = world

More Related Content

PPTX
Values and Data types in python
PPTX
PPTX
Data Types In Python.pptx
PDF
Module1PPT.pdf ,introduction to python programing
PPTX
Python Data-Types
PPTX
Variables&DataTypes.pptx
PPTX
python presentation.pptx
PPTX
Introduction to python
Values and Data types in python
Data Types In Python.pptx
Module1PPT.pdf ,introduction to python programing
Python Data-Types
Variables&DataTypes.pptx
python presentation.pptx
Introduction to python

Similar to 2. Values and Data types in Python.pptx (20)

PDF
Python Programminng…………………………………………………..
PPTX
Python-Basics.pptx
PPTX
introduction to python,datatypes,operators
PDF
Python Basics Understanding Variables.pdf
PDF
Python Basics Understanding Variables.pdf
PPTX
Python unit 2 is added. Has python related programming content
PPTX
1. python programming
PDF
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
PDF
"Automata Basics and Python Applications"
PDF
13- Data and Its Types presentation kafss
PPTX
Introduction to Python Programming for beginners
PPTX
Chapter - 2.pptx
PPTX
Chapter7-Introduction to Python.pptx
PDF
Lists and its functions in python for beginners
PPTX
unit1 python.pptx
PPTX
Programming Basics.pptx
PPTX
introduction to python
PPTX
pythondatatypes.pptx
PPTX
Lists on the pyhton to learn the children more easily on easy codes.pptx
PDF
E-Notes_3720_Content_Document_20250107032323PM.pdf
Python Programminng…………………………………………………..
Python-Basics.pptx
introduction to python,datatypes,operators
Python Basics Understanding Variables.pdf
Python Basics Understanding Variables.pdf
Python unit 2 is added. Has python related programming content
1. python programming
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
"Automata Basics and Python Applications"
13- Data and Its Types presentation kafss
Introduction to Python Programming for beginners
Chapter - 2.pptx
Chapter7-Introduction to Python.pptx
Lists and its functions in python for beginners
unit1 python.pptx
Programming Basics.pptx
introduction to python
pythondatatypes.pptx
Lists on the pyhton to learn the children more easily on easy codes.pptx
E-Notes_3720_Content_Document_20250107032323PM.pdf
Ad

Recently uploaded (20)

PDF
composite construction of structures.pdf
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
OOP with Java - Java Introduction (Basics)
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPT
Project quality management in manufacturing
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
Well-logging-methods_new................
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
DOCX
573137875-Attendance-Management-System-original
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Internet of Things (IOT) - A guide to understanding
composite construction of structures.pdf
Embodied AI: Ushering in the Next Era of Intelligent Systems
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Structs to JSON How Go Powers REST APIs.pdf
OOP with Java - Java Introduction (Basics)
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Project quality management in manufacturing
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Well-logging-methods_new................
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
UNIT 4 Total Quality Management .pptx
Foundation to blockchain - A guide to Blockchain Tech
573137875-Attendance-Management-System-original
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Internet of Things (IOT) - A guide to understanding
Ad

2. Values and Data types in Python.pptx

  • 1. Values and Data types in Python
  • 2. Value • A value is one of the fundamental things, like a number, a character or a string that program manipulates. Example 2,42.0,’Hello,World’ The value belong to different types.
  • 3. Literal Constants  The value of a literal constant can be used directly in programs. For example, 7, 3.9, 'A', and "Hello" are literal constants.  Numbers refers to a numeric value. You can use four types of numbers in Python program- integers, long integers, floating point and complex numbers.  Numbers like 5 or other whole numbers are referred to as integers. Bigger whole numbers are called long integers. For example, 535633629843L is a long integer.  Numbers like are 3.23 and 91.5E-2 are termed as floating point numbers.  Numbers of a + bi form (like -3 + 7i) are complex numbers. 9/5/2022 Introduction to python 3
  • 4. Example 9/5/2022 Introduction to python 4 Strings A string is a group of characters. • Using Single Quotes ('): For example, a string can be written as 'HELLO'. • Using Double Quotes ("): Strings in doubles are exactly same as those in single quotes. Therefore, 'HELLO' is same quoteas "HELLO". • Using Triple Quotes (''' '''): You can specify multi-line strings using triple quotes. You can use as many single quotes and double quotes as you want in a string within triple quotes. Examples:
  • 5. • 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 standard data types supported by python includes: – Number – Boolean – String – List – Tuple – Dictionary
  • 6. Numbers • Numbers refers to a numeric value. It includes integers, long integers, floating point, and complex numbers. • Integers are whole numbers with no fractional parts. They can be either positive, negative or zero value. Python displays long integers with an uppercase L (56788333354533L is a long integer). • 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’. • A 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.
  • 7. • 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. Example: 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 number?", isinstance(1+2j,complex)) Output: 5 is of type <class 'int'> 2.0 is of type <class 'float'> (1+2j) is complex number? True
  • 8. • Boolean is another data type in Python. • A variable of Boolean type can have one of the two values- True or False. 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 form 0 in Python. Example: >>>a = [5,10,15,20,25,30,35,40] >>>a[2] 15 >>>print("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) 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. Example: s = 'Hello world!' print("s[4] = ", s[4]) # s[4] = 'o' print("s[6:11] = ", s[6:11]) # s[6:11] = 'world' Output: s[4] = o s[6:11] = world