KnowledgeBoat Logo
|

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 :

  1. Single line Strings — These strings terminate in single line. For example, "I am a single line string" , "Hello World!"
  2. Multiline Strings — These strings spread across multiple lines. These strings are created in following two ways :
    1. by adding a backslash at the end of physical line, for example,
      multiline_string_variable = "Hello \
      World !"
    2. by enclosing the multiple lines of string in triple quotes, for example,
      Str1 = ''' Hello
      World.
      There I Come ! ! !
      Cheers.
      '''

Answered By

1 Like


Related Questions