Page 117 - Plus V4 with Adobe class 8
P. 117

There are two ways of indexing a string:

                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 6: To access different elements of a string













            You will get the following output:












            String Operators

            There are two basic string operators in Python, + and *. Python uses + for concatenation and * for
            replication:

               String Concatenation Operator (+): String concatenation operator joins two or more strings into
               one.


             Program 7: To join two or more strings using string concatenation operator
















            You will get the following output:














                                                                                  #Functions and String in Python 115
   112   113   114   115   116   117   118   119   120   121   122