Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 95 - 2612_Digimind
P. 95

    CREATING A SINGLE-LINE STRING
                     Single-line strings can be created by enclosing characters inside single or double quotes. It is like
                     assigning a value to a variable.

                     Program 4: To create a single-line string

                         Program4.py
                      File  Edit  Format   Run    Options   Window    Help

                      first_name = 'Aadya'
                      print (first_name)
                      last_name = 'Kaushal'
                      print (last_name)
                      str = ' '
                      print (str)

                         Output
                      Aadya
                      Kaushal

                     CREATING MULTILINE STRING

                     A multiline string in Python begins and ends with either three single quotes or three double quotes.
                     Any quotes, tabs or newlines in between the “triple quotes” are considered part of the string.

                     Program 5: To print multiline string
                         Program5.py

                      File  Edit  Format   Run    Options   Window    Help

                      print('''A sequence of
                      characters are called a string.
                      Strings are used by programming
                      languages to manipulate text such
                      as words and sentences.''')

                     You will get the following output:

                         Output

                      A sequence of
                      characters are called a string.
                      Strings are used by programming
                      languages to manipulate text such
                      as words and sentences.

                                                                                       Functions, String and List in Python  93

| 90 91 92 93 94 95 96 97 98 99 100 |