Page 69 - tp_Modula_v2.0
P. 69

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

                     Output

                  r
                  e




                     STRING OPERATORS

                 Various operations that can be performed on a string are Concatenating, Replicating, Membership
                 (in /not in), Comparison and Slicing.

                 String Concatenation Operator (+)


                 String concatenation operator (+) joins two or more strings into one.
                 Program 6: To join two or more strings using string concatenation operator.

                     Program6.py
                  File  Edit  Format  Run   Options   Window    Help
                  s1 = 'Hi!'
                  s2 = 'how are you'
                  s3 = '?'
                  s = s1 + s2 + s3
                  print(s)



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

                     Output

                  Hi!how are you?



                   String Replication Operator (*)


                 The replication operator is used to repeat the string for a given number of times.
                 Program 7: To repeat a string using string replication operator.
                     Program7.py
                  File  Edit  Format  Run   Options   Window    Help
                  s1 = 'Hi!'
                  s = s1 * 3
                  print(s)



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

                  Hi!Hi!Hi!






                                                                                      String Handling in Python   67
   64   65   66   67   68   69   70   71   72   73   74