Page 64 - Modular v1.1 Pyhton
P. 64

Using Escape Sequences

                  Escape sequences or characters are used to insert special characters that are invalid in Python.
                  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 which does not get displayed in output  when

                  used inside a character or a 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. It is used to represent white space characters, for example, ‘\t’ for tab, ‘\n’
                  for new line, and ‘\r’ is for carriage return.

                  Program 4: To print special symbols using escape sequences.









                  On running the above program, you will get the following output:
















                      TRAVERSING A STRING

                  Traversing means visiting each element and processing it as required by the program. We can
                  access the characters of a string one at a time using indexing.

                  There are two ways of indexing a list:

                      Index with positive integers: Index from left starts with 0.

                      Index with negative integers: Index from right starts with -1.

                      Syntax for traversing a string:

                          <name of the string> [index]
                      Program 5: To access different elements of a string.













                   62     Touchpad MODULAR (Version 1.0)
   59   60   61   62   63   64   65   66   67   68   69