iii)String:
String can be defined in three ways :
using single quotes, double quotes, triple single quotes or Double single
quotes.
"String_name" or 'string_name' are the basic way you can define a string.
A special provision for writing a multiline string is provided by python
using three quotes:
For example : """ I am a multiline comment
Which can be extended for any number of lines
.............
.............
String ends here """
Or, instead of """ comment """", ''' comment ''' can be used.
Note : Combination of quotes cannot be used. Either of the quotes
type has to be used.
By default, the string quotes used by python is ' '.
>>> "python3"
'python3'
>>> type(""" I am a
... multiline comment
... """)
<class 'str'>
>>> "hello "+"world"
'hello world'
Here, what interpreter has done is not addition of strings but
concatenation of strings.
Concatenation is appending of one string at the last of another
string.
String repetition:
>>> " I am repeating"*3
' I am repeating I am repeating I am repeating'
No comments:
Post a Comment