Python String Module

Python String Module consists of several useful constants, classes and functions. These functions are used to manipulate the strings.

['_re', '_string', 'ascii_letters', 'ascii_lowercase', 'ascii_uppercase', 'digits', 'hexdigits', 'octdigits', 'printable', 'punctuation', 'whitespace']

1. string.ascii_letters: Combination of ascii_lowercase and ascii_uppercase constants.

2. string.ascii_lowercase: It refers to all lowercase letters from a-z.

3. string.ascii_uppercase: It refers to all uppercase letters from A-Z.

4. string.digits: It refers to digits from 0-9.

5. string.hexdigits: It refers to hexadecimal digits 0-9, a-f, and A-F.

6. string.lowercase: A string that has all the characters that are considered lowercase letters.

7. string.uppercase: A string that has all the characters that are considered uppercase letters.

8. string.punctuation: A string of printable characters which includes digits, letters, punctuation, and whitespace.

9. string.octdigits: It refers to octal digits, 0-7.

10. string.whitespace: A string that has all characters that are considered whitespace like space, tab, linefeed, return, form-feed and vertical tab.


str="Welcome to Webeduclick"
print("Uppercase= ", str.upper())
print("Lowercase= ", str.lower())
print("Split= ", str.split())
print("Join= ", '_'.join(str.lower()))
print("Replace= ", str.replace("Webeduclick", "W3School"))
print("Count of e= ", str.count('e'))
print("Find to= ", str.find("to"))


Lowercase=  welcome to webeduclick
Split=  ['Welcome', 'to', 'Webeduclick']
Join=  w_e_l_c_o_m_e_ _t_o_ _w_e_b_e_d_u_c_l_i_c_k
Replace=  Welcome to W3School
Count of e=  4
Find to=  8