Page 101 - KEC Khaitan C8 Flipbook
P. 101
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 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:
len(string_name)
lower(): The lower() method returns a copy of the string with all characters converted to
lowercase.
Syntax:
string_name.lower()
upper(): The upper() method returns a copy of the string with all characters converted to
uppercase.
Syntax:
string_name.upper()
Functions, String and List in Python 99

