SlideShare a Scribd company logo
1 of 38
PYTHON
LECTURE 6
Today’s Agenda
More On DataTypes
• The floatType
• The complex Type
• The boolType
• The strType
The float DataType
• Python also supports floating-point real values.
• Float values are specified with a decimal point
• So 2.5 , 3.14 , 6.9 etc are all examples of float data type
• Just like double data type of other languages like Java/C ,
float in Python has a precision of 16 digits
Some Examples
Some Important Points
About float
• For float , we can only assign values in decimal number
system and not in binary , octal or hexadecimal number
system.
Some Important Points
About float
• Float values can also be represented as exponential values
• Exponential notation is a scientific notation which is
represented using e or E followed by an integer and it
means to the power of 10
The complex DataType
• Complex numbers are written in the form, x + yj, where x is
the real part and y is the imaginary part.
• For example: 4+3j , 12+1j etc
• The letter j is called unit imaginary number.
• It denotes the value of √-1 , i.e j² denotes -1
An Example
Some Important Points
About complex DataType
• For representing the unit imaginary number we are only
allowed to use the letter j (both upper and lower case are
allowed).
• Any other letter if used will generate error
Some Important Points
About complex DataType
• The letter j , should only appear in suffix , not in prefix
Some Important Points
About complex DataType
• The real and imaginary parts are allowed to be integers as
well as floats
Some Important Points
About complex DataType
• The real part can be specified in any int form i.e. decimal ,
binary , octal or hexadecimal but the imaginary part
should only be in decimal form
Some Important Points
About complex DataType
• We can display real and imaginary part separately by using
the attributes of complex types called “real” and “imag”.
• Don’t think real and imag are functions , rather they are
attributes/properties of complex data type
The bool DataType
• In Python , to represent boolean values we have bool data
type.
• The bool data type can be one of two values,
either True or False.
• We use Booleans in programming to make comparisons
and to control the flow of the program.
Some Examples
Some Important Points
About bool
• True and False are keywords , so case sensitivity must be
remembered while assigning them otherwise Python will
give error
Some Important Points
About bool
• All test conditions in Python return the result as bool
which could be either True or False
Some Important Points
About bool
• To understand the next point , try to guess the output of the
following:
a=True
b=False
c=a+b
print(c)
Output:
1
a=True
b=True
c=a+b
print(c)
Output:
2
a=False
b=False
c=a+b
print(c)
Output:
0
The above outputs make it clear that internally Python stores
True and False as integers with the value 1 and 0 respectively
The str DataType
• Just like any other language , in Python also a String is
sequence of characters.
• Python does not have a char data type, unlike C/C++ or
Java
• We can use single quotes or double quotes to represent
strings.
• However Python recommends to use single quotes
Some Examples
The data type used by Python internally for storing Strings is
str
Some Important Points
About Strings
• Unlike C language , Python does not uses ASCII number
system for characters . It uses UNICODE number system
• UNICODE is a number system which supports much wider
range of characters compared to ASCII
• As far as Python is concerned , it uses UNICODE to support
65536 characters with their numeric values ranging from 0
to 65535 which covers almost every spoken language in the
world like English , Greek , Spanish , Chinese , Japanese
etc
Some Important Points
About Strings
Some Important Points
About Strings
• Whenever we display a string value directly on Python’s
shell i.e. without using the function print(), Python’s shell
automatically encloses it in single quotes
• However this does not happen when we use print() function
to print a string value
Some Important Points
About Strings
• If a string starts with double quotes , it must end with
double quotes only .
• Similarly if it starts with single quotes , it must end with
single quotes only.
• Otherwise Python will generate error
Some Important Points
About Strings
Some Important Points
About Strings
• If the string contains single quotes in between then it must
be enclosed in double quotes and vice versa.
• For example:
• To print Sachin's Python Classes , we would write:
• msg= " Sachin's Python Classes "
• Similarly to print Capital of "MP" is "Bhopal" ,we would
write:
• msg='Capital of "MP" is "Bhopal" '
Some Important Points
About Strings
Some Important Points
About Strings
• How will you print Let's learn "Python" ?
A. "Let's learn "Python" "
B. 'Let's learn "Python" '
NONE!
Both will give error.
Correct way is to use either triple single quotes or triple
double quotes or escape sequence character 
msg=' ' 'Let's learn "Python" ' ' '
OR
msg='Let's learn "Python" '
Some Important Points
About Strings
Some Important Points
About Strings
Some Important Points
About Strings
• Another important use of triple single quotes or triple
double quotes is that if our string extends up to more than
1 line then we need to enclose it in triple single quotes or
triple double quotes
Some Important Points
About Strings
• We also can do the same thing by using n , so using triple
quotes or triple double quotes is just for improving
readability
Accessing Individual Characters
In String
 In Python, all Strings are stored as individual characters in a
contiguous memory location.
 Each character in this memory location is assigned an index
which begins from 0 and goes up to length -1
Accessing Individual Characters
In String
 For example, suppose we write
word=“Python”
 Then the internal representation of this will be
Accessing Individual Characters
In String
 Now to access individual character we can provide this index
number to the subscript operator [ ].
Accessing Individual Characters
In String
 However if we try to provide an index number beyond the given
limit then IndexError exception will arise
Accessing Individual Characters
In String
 Not only this , Python even allows negative indexing which
begins from the end of the string.
 So -1 is the index of last character , -2 is the index of second
last character and so on.
Accessing Individual Characters
In String

More Related Content

Similar to 06.pptx

presentation_python_7_1569170870_375360.pptx
presentation_python_7_1569170870_375360.pptxpresentation_python_7_1569170870_375360.pptx
presentation_python_7_1569170870_375360.pptx
ansariparveen06
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 

Similar to 06.pptx (20)

Python revision tour i
Python revision tour iPython revision tour i
Python revision tour i
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Unit-I-PPT-1.ppt
Unit-I-PPT-1.pptUnit-I-PPT-1.ppt
Unit-I-PPT-1.ppt
 
An overview on python commands for solving the problems
An overview on python commands for solving the problemsAn overview on python commands for solving the problems
An overview on python commands for solving the problems
 
Python - Module 1.ppt
Python - Module 1.pptPython - Module 1.ppt
Python - Module 1.ppt
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
Python-Basics.pptx
Python-Basics.pptxPython-Basics.pptx
Python-Basics.pptx
 
unit1 python.pptx
unit1 python.pptxunit1 python.pptx
unit1 python.pptx
 
01 Java Language And OOP PART I
01 Java Language And OOP PART I01 Java Language And OOP PART I
01 Java Language And OOP PART I
 
Chapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptxChapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptx
 
Python 01.pptx
Python 01.pptxPython 01.pptx
Python 01.pptx
 
introduction to python
 introduction to python introduction to python
introduction to python
 
2. python basic syntax
2. python   basic syntax2. python   basic syntax
2. python basic syntax
 
2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptx2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptx
 
Introduction to Python Part-1
Introduction to Python Part-1Introduction to Python Part-1
Introduction to Python Part-1
 
presentation_python_7_1569170870_375360.pptx
presentation_python_7_1569170870_375360.pptxpresentation_python_7_1569170870_375360.pptx
presentation_python_7_1569170870_375360.pptx
 
modul-python-part1.pptx
modul-python-part1.pptxmodul-python-part1.pptx
modul-python-part1.pptx
 
Python_Unit_1.pdf
Python_Unit_1.pdfPython_Unit_1.pdf
Python_Unit_1.pdf
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
 
Python PPT.pptx
Python PPT.pptxPython PPT.pptx
Python PPT.pptx
 

More from saiproject

Visual Communication and Design for PowerPoint Presentations .ppt
Visual Communication and Design for PowerPoint Presentations .pptVisual Communication and Design for PowerPoint Presentations .ppt
Visual Communication and Design for PowerPoint Presentations .ppt
saiproject
 
4th sem project.pptx
4th sem project.pptx4th sem project.pptx
4th sem project.pptx
saiproject
 
Verrucous leukoplakia.pptx
Verrucous leukoplakia.pptxVerrucous leukoplakia.pptx
Verrucous leukoplakia.pptx
saiproject
 
Medical Shop - 2.pptx
Medical Shop - 2.pptxMedical Shop - 2.pptx
Medical Shop - 2.pptx
saiproject
 
Study and evaluation of Pulsatile Drug delivery system.docx
Study and evaluation of Pulsatile Drug delivery system.docxStudy and evaluation of Pulsatile Drug delivery system.docx
Study and evaluation of Pulsatile Drug delivery system.docx
saiproject
 
major project 1-1 (1).pptx
major project 1-1 (1).pptxmajor project 1-1 (1).pptx
major project 1-1 (1).pptx
saiproject
 
WATER CONSERVATION TANANJAY RICCHARIYA.pptx
WATER CONSERVATION TANANJAY RICCHARIYA.pptxWATER CONSERVATION TANANJAY RICCHARIYA.pptx
WATER CONSERVATION TANANJAY RICCHARIYA.pptx
saiproject
 
OCBS UNIT 1(2).pptx
OCBS UNIT 1(2).pptxOCBS UNIT 1(2).pptx
OCBS UNIT 1(2).pptx
saiproject
 
Smart Health Disease Prediction django machinelearning.pptx
Smart Health Disease Prediction django machinelearning.pptxSmart Health Disease Prediction django machinelearning.pptx
Smart Health Disease Prediction django machinelearning.pptx
saiproject
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
saiproject
 
Blockchain Experiments 1-11.pptx
Blockchain Experiments 1-11.pptxBlockchain Experiments 1-11.pptx
Blockchain Experiments 1-11.pptx
saiproject
 

More from saiproject (20)

AMIT POWERPOINA doctor appointment booking system is an online system that al...
AMIT POWERPOINA doctor appointment booking system is an online system that al...AMIT POWERPOINA doctor appointment booking system is an online system that al...
AMIT POWERPOINA doctor appointment booking system is an online system that al...
 
Visual Communication and Design for PowerPoint Presentations .ppt
Visual Communication and Design for PowerPoint Presentations .pptVisual Communication and Design for PowerPoint Presentations .ppt
Visual Communication and Design for PowerPoint Presentations .ppt
 
4th sem project.pptx
4th sem project.pptx4th sem project.pptx
4th sem project.pptx
 
Verrucous leukoplakia.pptx
Verrucous leukoplakia.pptxVerrucous leukoplakia.pptx
Verrucous leukoplakia.pptx
 
Medical Shop - 2.pptx
Medical Shop - 2.pptxMedical Shop - 2.pptx
Medical Shop - 2.pptx
 
Presentation1.pptx
Presentation1.pptxPresentation1.pptx
Presentation1.pptx
 
Study and evaluation of Pulsatile Drug delivery system.docx
Study and evaluation of Pulsatile Drug delivery system.docxStudy and evaluation of Pulsatile Drug delivery system.docx
Study and evaluation of Pulsatile Drug delivery system.docx
 
Ram minor project PPT..pptx
Ram minor project PPT..pptxRam minor project PPT..pptx
Ram minor project PPT..pptx
 
ppt.pptx
ppt.pptxppt.pptx
ppt.pptx
 
Pawan ppt.pptx
Pawan ppt.pptxPawan ppt.pptx
Pawan ppt.pptx
 
priyankamainthesisppt.pptx
priyankamainthesisppt.pptxpriyankamainthesisppt.pptx
priyankamainthesisppt.pptx
 
anurag14[1].ppt
anurag14[1].pptanurag14[1].ppt
anurag14[1].ppt
 
major project 1-1 (1).pptx
major project 1-1 (1).pptxmajor project 1-1 (1).pptx
major project 1-1 (1).pptx
 
garibi.pptx
garibi.pptxgaribi.pptx
garibi.pptx
 
WATER CONSERVATION TANANJAY RICCHARIYA.pptx
WATER CONSERVATION TANANJAY RICCHARIYA.pptxWATER CONSERVATION TANANJAY RICCHARIYA.pptx
WATER CONSERVATION TANANJAY RICCHARIYA.pptx
 
OCBS UNIT 1(2).pptx
OCBS UNIT 1(2).pptxOCBS UNIT 1(2).pptx
OCBS UNIT 1(2).pptx
 
CASTING PROCEDURE part 2
 CASTING PROCEDURE part 2 CASTING PROCEDURE part 2
CASTING PROCEDURE part 2
 
Smart Health Disease Prediction django machinelearning.pptx
Smart Health Disease Prediction django machinelearning.pptxSmart Health Disease Prediction django machinelearning.pptx
Smart Health Disease Prediction django machinelearning.pptx
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
Blockchain Experiments 1-11.pptx
Blockchain Experiments 1-11.pptxBlockchain Experiments 1-11.pptx
Blockchain Experiments 1-11.pptx
 

Recently uploaded

Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
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
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 

Recently uploaded (20)

Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
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
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
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
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
(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
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 

06.pptx

  • 2. Today’s Agenda More On DataTypes • The floatType • The complex Type • The boolType • The strType
  • 3. The float DataType • Python also supports floating-point real values. • Float values are specified with a decimal point • So 2.5 , 3.14 , 6.9 etc are all examples of float data type • Just like double data type of other languages like Java/C , float in Python has a precision of 16 digits
  • 5. Some Important Points About float • For float , we can only assign values in decimal number system and not in binary , octal or hexadecimal number system.
  • 6. Some Important Points About float • Float values can also be represented as exponential values • Exponential notation is a scientific notation which is represented using e or E followed by an integer and it means to the power of 10
  • 7. The complex DataType • Complex numbers are written in the form, x + yj, where x is the real part and y is the imaginary part. • For example: 4+3j , 12+1j etc • The letter j is called unit imaginary number. • It denotes the value of √-1 , i.e j² denotes -1
  • 9. Some Important Points About complex DataType • For representing the unit imaginary number we are only allowed to use the letter j (both upper and lower case are allowed). • Any other letter if used will generate error
  • 10. Some Important Points About complex DataType • The letter j , should only appear in suffix , not in prefix
  • 11. Some Important Points About complex DataType • The real and imaginary parts are allowed to be integers as well as floats
  • 12. Some Important Points About complex DataType • The real part can be specified in any int form i.e. decimal , binary , octal or hexadecimal but the imaginary part should only be in decimal form
  • 13. Some Important Points About complex DataType • We can display real and imaginary part separately by using the attributes of complex types called “real” and “imag”. • Don’t think real and imag are functions , rather they are attributes/properties of complex data type
  • 14. The bool DataType • In Python , to represent boolean values we have bool data type. • The bool data type can be one of two values, either True or False. • We use Booleans in programming to make comparisons and to control the flow of the program.
  • 16. Some Important Points About bool • True and False are keywords , so case sensitivity must be remembered while assigning them otherwise Python will give error
  • 17. Some Important Points About bool • All test conditions in Python return the result as bool which could be either True or False
  • 18. Some Important Points About bool • To understand the next point , try to guess the output of the following: a=True b=False c=a+b print(c) Output: 1 a=True b=True c=a+b print(c) Output: 2 a=False b=False c=a+b print(c) Output: 0 The above outputs make it clear that internally Python stores True and False as integers with the value 1 and 0 respectively
  • 19. The str DataType • Just like any other language , in Python also a String is sequence of characters. • Python does not have a char data type, unlike C/C++ or Java • We can use single quotes or double quotes to represent strings. • However Python recommends to use single quotes
  • 20. Some Examples The data type used by Python internally for storing Strings is str
  • 21. Some Important Points About Strings • Unlike C language , Python does not uses ASCII number system for characters . It uses UNICODE number system • UNICODE is a number system which supports much wider range of characters compared to ASCII • As far as Python is concerned , it uses UNICODE to support 65536 characters with their numeric values ranging from 0 to 65535 which covers almost every spoken language in the world like English , Greek , Spanish , Chinese , Japanese etc
  • 23. Some Important Points About Strings • Whenever we display a string value directly on Python’s shell i.e. without using the function print(), Python’s shell automatically encloses it in single quotes • However this does not happen when we use print() function to print a string value
  • 24. Some Important Points About Strings • If a string starts with double quotes , it must end with double quotes only . • Similarly if it starts with single quotes , it must end with single quotes only. • Otherwise Python will generate error
  • 26. Some Important Points About Strings • If the string contains single quotes in between then it must be enclosed in double quotes and vice versa. • For example: • To print Sachin's Python Classes , we would write: • msg= " Sachin's Python Classes " • Similarly to print Capital of "MP" is "Bhopal" ,we would write: • msg='Capital of "MP" is "Bhopal" '
  • 28. Some Important Points About Strings • How will you print Let's learn "Python" ? A. "Let's learn "Python" " B. 'Let's learn "Python" ' NONE! Both will give error. Correct way is to use either triple single quotes or triple double quotes or escape sequence character msg=' ' 'Let's learn "Python" ' ' ' OR msg='Let's learn "Python" '
  • 31. Some Important Points About Strings • Another important use of triple single quotes or triple double quotes is that if our string extends up to more than 1 line then we need to enclose it in triple single quotes or triple double quotes
  • 32. Some Important Points About Strings • We also can do the same thing by using n , so using triple quotes or triple double quotes is just for improving readability
  • 33. Accessing Individual Characters In String  In Python, all Strings are stored as individual characters in a contiguous memory location.  Each character in this memory location is assigned an index which begins from 0 and goes up to length -1
  • 34. Accessing Individual Characters In String  For example, suppose we write word=“Python”  Then the internal representation of this will be
  • 35. Accessing Individual Characters In String  Now to access individual character we can provide this index number to the subscript operator [ ].
  • 36. Accessing Individual Characters In String  However if we try to provide an index number beyond the given limit then IndexError exception will arise
  • 37. Accessing Individual Characters In String  Not only this , Python even allows negative indexing which begins from the end of the string.  So -1 is the index of last character , -2 is the index of second last character and so on.