Computer Applications
What are string-literals in Python ? How many ways, can you create String literals in Python ?
Python Funda
3 Likes
Answer
We can form string literals by enclosing text in both forms of quotes — single quotes or double quotes. For example, 'Astha', "Rizwan", 'Hello World', "112FB0291", etc.
Python allows us to have two string types :
- Single line Strings — These strings terminate in single line. For example, "I am a single line string" , "Hello World!"
- Multiline Strings — These strings spread across multiple lines. These strings are created in following two ways :
- by adding a backslash at the end of physical line, for example,
multiline_string_variable = "Hello \
World !" - by enclosing the multiple lines of string in triple quotes, for example,
Str1 = ''' Hello
World.
There I Come ! ! !
Cheers.
'''
- by adding a backslash at the end of physical line, for example,
Answered By
1 Like