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
Ad

More Related Content

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

Python Basics Understanding Variables.pdf
Python Basics Understanding Variables.pdfPython Basics Understanding Variables.pdf
Python Basics Understanding Variables.pdf
codingmaster021
 
Python Basics Understanding Variables.pdf
Python Basics Understanding Variables.pdfPython Basics Understanding Variables.pdf
Python Basics Understanding Variables.pdf
codingmaster021
 
Python unit 2 is added. Has python related programming content
Python unit 2 is added. Has python related programming contentPython unit 2 is added. Has python related programming content
Python unit 2 is added. Has python related programming content
swarna16
 
1. python programming
1. python programming1. python programming
1. python programming
sreeLekha51
 
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
rajkumar2792005
 
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
AliKhokhar33
 
Introduction to Python Programming for beginners
Introduction to Python Programming for beginnersIntroduction to Python Programming for beginners
Introduction to Python Programming for beginners
MuhammadUsman406079
 
Chapter - 2.pptx
Chapter - 2.pptxChapter - 2.pptx
Chapter - 2.pptx
MikialeTesfamariam
 
Chapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptxChapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptx
lemonchoos
 
Lists and its functions in python for beginners
Lists and its functions in python for beginnersLists and its functions in python for beginners
Lists and its functions in python for beginners
Mohammad Usman
 
unit1 python.pptx
unit1 python.pptxunit1 python.pptx
unit1 python.pptx
TKSanthoshRao
 
Programming Basics.pptx
Programming Basics.pptxProgramming Basics.pptx
Programming Basics.pptx
mahendranaik18
 
introduction to python
 introduction to python introduction to python
introduction to python
Jincy Nelson
 
pythondatatypes.pptx
pythondatatypes.pptxpythondatatypes.pptx
pythondatatypes.pptx
ArchanaAravind1
 
E-Notes_3720_Content_Document_20250107032323PM.pdf
E-Notes_3720_Content_Document_20250107032323PM.pdfE-Notes_3720_Content_Document_20250107032323PM.pdf
E-Notes_3720_Content_Document_20250107032323PM.pdf
aayushihirpara297
 
data type of pythonpython pytohn datagsdkghmkedhm,fdlbm
data type of pythonpython pytohn datagsdkghmkedhm,fdlbmdata type of pythonpython pytohn datagsdkghmkedhm,fdlbm
data type of pythonpython pytohn datagsdkghmkedhm,fdlbm
dibyashakti10
 
Presentation on python data type
Presentation on python data typePresentation on python data type
Presentation on python data type
swati kushwaha
 
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
 
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
Rushikesh Kolhe
 
1691912901477_Python_Basics and list,tuple,string.pptx
1691912901477_Python_Basics and list,tuple,string.pptx1691912901477_Python_Basics and list,tuple,string.pptx
1691912901477_Python_Basics and list,tuple,string.pptx
KUSHSHARMA630049
 
Python Basics Understanding Variables.pdf
Python Basics Understanding Variables.pdfPython Basics Understanding Variables.pdf
Python Basics Understanding Variables.pdf
codingmaster021
 
Python Basics Understanding Variables.pdf
Python Basics Understanding Variables.pdfPython Basics Understanding Variables.pdf
Python Basics Understanding Variables.pdf
codingmaster021
 
Python unit 2 is added. Has python related programming content
Python unit 2 is added. Has python related programming contentPython unit 2 is added. Has python related programming content
Python unit 2 is added. Has python related programming content
swarna16
 
1. python programming
1. python programming1. python programming
1. python programming
sreeLekha51
 
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
rajkumar2792005
 
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
AliKhokhar33
 
Introduction to Python Programming for beginners
Introduction to Python Programming for beginnersIntroduction to Python Programming for beginners
Introduction to Python Programming for beginners
MuhammadUsman406079
 
Chapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptxChapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptx
lemonchoos
 
Lists and its functions in python for beginners
Lists and its functions in python for beginnersLists and its functions in python for beginners
Lists and its functions in python for beginners
Mohammad Usman
 
Programming Basics.pptx
Programming Basics.pptxProgramming Basics.pptx
Programming Basics.pptx
mahendranaik18
 
introduction to python
 introduction to python introduction to python
introduction to python
Jincy Nelson
 
E-Notes_3720_Content_Document_20250107032323PM.pdf
E-Notes_3720_Content_Document_20250107032323PM.pdfE-Notes_3720_Content_Document_20250107032323PM.pdf
E-Notes_3720_Content_Document_20250107032323PM.pdf
aayushihirpara297
 
data type of pythonpython pytohn datagsdkghmkedhm,fdlbm
data type of pythonpython pytohn datagsdkghmkedhm,fdlbmdata type of pythonpython pytohn datagsdkghmkedhm,fdlbm
data type of pythonpython pytohn datagsdkghmkedhm,fdlbm
dibyashakti10
 
Presentation on python data type
Presentation on python data typePresentation on python data type
Presentation on python data type
swati kushwaha
 
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
 
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
Rushikesh Kolhe
 
1691912901477_Python_Basics and list,tuple,string.pptx
1691912901477_Python_Basics and list,tuple,string.pptx1691912901477_Python_Basics and list,tuple,string.pptx
1691912901477_Python_Basics and list,tuple,string.pptx
KUSHSHARMA630049
 

Recently uploaded (20)

Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Journal of Soft Computing in Civil Engineering
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdfML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
rameshwarchintamani
 
Modeling the Influence of Environmental Factors on Concrete Evaporation Rate
Modeling the Influence of Environmental Factors on Concrete Evaporation RateModeling the Influence of Environmental Factors on Concrete Evaporation Rate
Modeling the Influence of Environmental Factors on Concrete Evaporation Rate
Journal of Soft Computing in Civil Engineering
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
David Boutry - Specializes In AWS, Microservices And Python
David Boutry - Specializes In AWS, Microservices And PythonDavid Boutry - Specializes In AWS, Microservices And Python
David Boutry - Specializes In AWS, Microservices And Python
David Boutry
 
Automatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and BeyondAutomatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and Beyond
NU_I_TODALAB
 
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
ijdmsjournal
 
Physical and Physic-Chemical Based Optimization Methods: A Review
Physical and Physic-Chemical Based Optimization Methods: A ReviewPhysical and Physic-Chemical Based Optimization Methods: A Review
Physical and Physic-Chemical Based Optimization Methods: A Review
Journal of Soft Computing in Civil Engineering
 
Personal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.pptPersonal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.ppt
ganjangbegu579
 
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdfATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ssuserda39791
 
AI-Powered Data Management and Governance in Retail
AI-Powered Data Management and Governance in RetailAI-Powered Data Management and Governance in Retail
AI-Powered Data Management and Governance in Retail
IJDKP
 
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
Guru Nanak Technical Institutions
 
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning ModelsMode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Journal of Soft Computing in Civil Engineering
 
22PCOAM16_MACHINE_LEARNING_UNIT_IV_NOTES_with_QB
22PCOAM16_MACHINE_LEARNING_UNIT_IV_NOTES_with_QB22PCOAM16_MACHINE_LEARNING_UNIT_IV_NOTES_with_QB
22PCOAM16_MACHINE_LEARNING_UNIT_IV_NOTES_with_QB
Guru Nanak Technical Institutions
 
AI Chatbots & Software Development Teams
AI Chatbots & Software Development TeamsAI Chatbots & Software Development Teams
AI Chatbots & Software Development Teams
Joe Krall
 
Construction-Chemicals-For-Waterproofing.ppt
Construction-Chemicals-For-Waterproofing.pptConstruction-Chemicals-For-Waterproofing.ppt
Construction-Chemicals-For-Waterproofing.ppt
ssuser2ffcbc
 
Machine Learning basics POWERPOINT PRESENETATION
Machine Learning basics POWERPOINT PRESENETATIONMachine Learning basics POWERPOINT PRESENETATION
Machine Learning basics POWERPOINT PRESENETATION
DarrinBright1
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdfML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
rameshwarchintamani
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
David Boutry - Specializes In AWS, Microservices And Python
David Boutry - Specializes In AWS, Microservices And PythonDavid Boutry - Specializes In AWS, Microservices And Python
David Boutry - Specializes In AWS, Microservices And Python
David Boutry
 
Automatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and BeyondAutomatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and Beyond
NU_I_TODALAB
 
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
ijdmsjournal
 
Personal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.pptPersonal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.ppt
ganjangbegu579
 
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdfATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ssuserda39791
 
AI-Powered Data Management and Governance in Retail
AI-Powered Data Management and Governance in RetailAI-Powered Data Management and Governance in Retail
AI-Powered Data Management and Governance in Retail
IJDKP
 
AI Chatbots & Software Development Teams
AI Chatbots & Software Development TeamsAI Chatbots & Software Development Teams
AI Chatbots & Software Development Teams
Joe Krall
 
Construction-Chemicals-For-Waterproofing.ppt
Construction-Chemicals-For-Waterproofing.pptConstruction-Chemicals-For-Waterproofing.ppt
Construction-Chemicals-For-Waterproofing.ppt
ssuser2ffcbc
 
Machine Learning basics POWERPOINT PRESENETATION
Machine Learning basics POWERPOINT PRESENETATIONMachine Learning basics POWERPOINT PRESENETATION
Machine Learning basics POWERPOINT PRESENETATION
DarrinBright1
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
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
  翻译: