Page 101 - KEC Khaitan C7 Flipbook
P. 101

Program 8: To print multiline string
                     Program8.py

                  File  Edit  Format   Run    Options   Window    Help

                  print('''A sequence of
                  characters are called a string.
                  Strings are used by programming
                  languages to manipulate text such
                  as words and sentences.''')


                 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.



                 STRING OPERATORS

                 There are two basic string operators in Python, + and *. Python uses + for concatenation and * for
                 replication. The description of these operators are as follows:
                   String Concatenation Operator (+): String concatenation operator joins two or more strings
                   into one.

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

                      Program9.py
                   File  Edit  Format  Run    Options  Window    Help

                   s1 = 'Here'
                   s2 = 'Is'
                   s3 = 'Python'
                   s = s1 + s2 + s3                                                Output
                   print(s)                                                      HereIsPython



                   String Replication Operator (*): The replication operator is used to repeat the string for a
                   given number of times.
                 Program 10: To repeat a string using string replication operator

                      Program10.py
                    File  Edit  Format  Run   Options   Window    Help

                    s1 = 'Hello'
                    s = s1 * 3                                                   Output
                    print(s)                                                   HelloHelloHello





                                                                                        Control Structures in Python  99
   96   97   98   99   100   101   102   103   104   105   106