Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 134 - 2609_Logicode
P. 134

    STRING

                      A sequence of characters which is enclosed or surrounded by single (' '), double (" "), or Triple
                      ('''  ''') quotes is known as a string. The sequence may include a letter, number, special characters
                      or a backslash. Python treats single quotes as double quotes.

                      Program 1: To print a string

                           Program1.py
                        File  Edit  Format  Run    Options  Window    Help
                        str = "This is Shweta's pen."                              Output
                        print(str)                                              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 2: To create a single-line string

                          Program2.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 3: To print multiline string

                      132   Premium Edition-VIII

| 129 130 131 132 133 134 135 136 137 138 139 |