Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 97 - 2611_SmartGPT Pro V(5.0) C-8
P. 97

    Example of a string:

                     str = 'This is Shweta\'s pen.'
                     print (str)
                     Output:

                     This is Shweta's pen.

                     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 3: To create a single-line string

                         Program3.py                                               Output
                      File  Edit  Format  Run    Options  Window    Help        Aadya

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

                     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 4: To print multiline string

                         Program4.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 and String in Python  95

| 92 93 94 95 96 97 98 99 100 101 102 |