Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 88 - 2607_Traclpad_Pro_5.1_flipbook_C8
P. 88

    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 STRING

                     Escape sequences or characters are used to represent special characters that  cannot be directly
                     inserted into a string.
                     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. To include special characters like quotes within a string, you need to escape
                     them with a backslash. 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 6: To print special symbols using escape sequences.

                         Program6.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 list:

                       Positive Indexing: Index from left starts with 0.

                       Negative Indexing: Index from right starts with -1.
                     The syntax for traversing a string is as follows:

                       <name of the string> [index]

                                                                                       Functions, String and List in Python  87

| 83 84 85 86 87 88 89 90 91 92 93 |