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

Mais conteúdo relacionado

Semelhante a 2. Values and Data types in Python.pptx

CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docxCS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
faithxdunce63732
 

Semelhante a 2. Values and Data types in Python.pptx (20)

1. python programming
1. python programming1. python programming
1. python programming
 
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdfCOMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
 
13- Data and Its Types presentation kafss
13- Data and Its Types presentation kafss13- Data and Its Types presentation kafss
13- Data and Its Types presentation kafss
 
Chapter - 2.pptx
Chapter - 2.pptxChapter - 2.pptx
Chapter - 2.pptx
 
Chapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptxChapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptx
 
unit1 python.pptx
unit1 python.pptxunit1 python.pptx
unit1 python.pptx
 
Programming Basics.pptx
Programming Basics.pptxProgramming Basics.pptx
Programming Basics.pptx
 
introduction to python
 introduction to python introduction to python
introduction to python
 
pythondatatypes.pptx
pythondatatypes.pptxpythondatatypes.pptx
pythondatatypes.pptx
 
Presentation on python data type
Presentation on python data typePresentation on python data type
Presentation on python data type
 
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docxCS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
 
Programming in Civil Engineering_UNIT 2_NOTES
Programming in Civil Engineering_UNIT 2_NOTESProgramming in Civil Engineering_UNIT 2_NOTES
Programming in Civil Engineering_UNIT 2_NOTES
 
trisha comp ppt.pptx
trisha comp ppt.pptxtrisha comp ppt.pptx
trisha comp ppt.pptx
 
MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptx
 
AI_2nd Lab.pptx
AI_2nd Lab.pptxAI_2nd Lab.pptx
AI_2nd Lab.pptx
 
Python
PythonPython
Python
 
intro to python.pptx
intro to python.pptxintro to python.pptx
intro to python.pptx
 
02 Python Data Structure.pptx
02 Python Data Structure.pptx02 Python Data Structure.pptx
02 Python Data Structure.pptx
 
Python data type
Python data typePython data type
Python data type
 
tupple.pptx
tupple.pptxtupple.pptx
tupple.pptx
 

Último

VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
dharasingh5698
 

Último (20)

(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 

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