Page 99 - KEC Khaitan C8 Flipbook
P. 99

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 3: To print a string

                     Program3.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 string 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 STRINGS

                 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.









                                                                                   Functions, String and List in Python  97
   94   95   96   97   98   99   100   101   102   103   104