Page 120 - Trackpad_V4.0_C8_Flipbook
P. 120

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 not directly printable or
              representable in a string in Python. They 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 special characters and formatting
              actions. For example, 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')




              You will get the following output:

                   Output

                I love programming in
                 Python



              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 string:

                  Positive Indexing: Indexing starts from the left, with the first character at index 0.
                  Negative Indexing: Indexing starts from the right, with the last character at index -1.




                        Premium Edition-VIII
                118
   115   116   117   118   119   120   121   122   123   124   125