Page 119 - TP_Play_V2.2_Class8
P. 119

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.




                 Using Escape Sequences with Strings

                 Escape sequences or characters are used to insert special characters that are invalid as a string in
                 python. It represent non-printable or special characters within strings. Quotes are special characters
                 and to insert them in a string we must escape them with a \ character in front of them.

                 An escape sequence is a sequence of characters that does not represent itself when used inside a
                 character or string. It is typically used to specify actions such as carriage returns and tab movements.
                 The backslash (\) is a special character and is also known as the escape character in Python. For example,
                 '\t' for tab, '\n' for new line, and '\r' is for carriage return.

                 Program 5: To print special symbols using escape sequences

                     Program5.py
                  File  Edit  Format   Run   Options   Window    Help


                  print('I love programming in \n Python')












                                                                                      #Functions and Strings in Python 117
   114   115   116   117   118   119   120   121   122   123   124