Home | | Computer Science 12th Std | Creating Strings

Python - Creating Strings | 12th Computer Science : Chapter 8 : Core Python : Strings and String Manipulation

Chapter: 12th Computer Science : Chapter 8 : Core Python : Strings and String Manipulation

Creating Strings

String in single quotes cannot hold any other single quoted character in it, because the compiler will not recognize where to start and end the string.

Creating Strings

As we learnt already, a string in Python can be created using single or double or even triple quotes. String in single quotes cannot hold any other single quoted character in it, because the compiler will not recognize where to start and end the string. To overcome this problem, you have to use double quotes. Strings which contains double quotes should be define within triple quotes. Defining strings within triple quotes also allows creation of multiline strings.

Example

#A string defined within single quotes

>>>print (‘Greater Chennai Corporation’) Greater Chennai Corporation

#single quoted string defined within single quotes

>>>print ('Greater Chennai Corporation's student') SyntaxError: invalid syntax

#A string defined within double quotes

>>>print (“Computer Science”)

Computer Science

#double quoted string defined within double quotes

>>>print (''' "Computer Science" ''')

"Computer Science"

#single and double quoted multiline string defined within triple quotes

>>> print (''' "Strings are immutable in 'Python',

which means you can't make any changes once you declared" ''')

"Strings are immutable in 'Python',

which means you can't make any changes once you declared"

 

Tags : Python , 12th Computer Science : Chapter 8 : Core Python : Strings and String Manipulation
Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
12th Computer Science : Chapter 8 : Core Python : Strings and String Manipulation : Creating Strings | Python


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.