Page 135 - 2620_Birla Open Mind C-8
P. 135

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

                      Program7.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 8: To repeat a string using string replication operator

                      Program8.py

                   File  Edit  Format   Run    Options   Window    Help

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




                 String Built-in Functions

                 Python includes the following built-in functions to manipulate strings:

                    len(): The len() function calculates and returns the length of a string supplied as an argument. Syntax
                    of using len() function is:

                    len(string_name)

                    lower(): The lower() function converts all uppercase letters to lowercase. Syntax of using lower()
                    function is:

                    string_name.lower()

                    upper(): The upper() function converts all lowercase letters to uppercase. Syntax of using upper()
                    function is:

                    string_name.upper()

                    capitalize(): The capitalize() function returns a string with the first character in capital. Syntax of
                    using capitalize() function is:

                    string_name.capitalize()




                                                                                      #Functions and Strings in Python 133
   130   131   132   133   134   135   136   137   138   139   140