Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 97 - 2612_Digimind
P. 97

    Output
                      o
                      e

                     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 8: To join two or more strings using string concatenation operator

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

                         Program9.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()

                                                                                       Functions, String and List in Python  95

| 92 93 94 95 96 97 98 99 100 101 102 |