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.
#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"
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.