Chapter 3 String, List, Tuple & Dictionary Functions
Chapter 3 String, List, Tuple & Dictionary Functions
Example: Example:
ord("a") : 97 chr(97) : “a"
ord("Z") : 90 chr(90) : “Z"
Strings Functions & Methods:
1. string.capitalize():
It gives the copy of string with its first character capitalized.
Example:
if t = "sumitrana” then R= t.capitalize()
will create a copy of string in R as,
R = "Sumitrana“
2. string.find(subString[,start [,end]):
It returns the lowest index in the string where the sub string is found
with in the slice range of start & end, returns -1 if sub string not
found.
Example:
t="We are learning Strings. Strings are used in Python"
k = "Strings"
t.find(k) Output: 16 (index no.)
t.find(k,20) Output : 25 (index no.)
t.find(k,20,30) Output: -1 will search from index 20 to 30
t.find(“Hello”) Output: -1 ( as string is not found)
Strings Functions & Methods:
3. string.isalnum(): It gives True, if the characters in
the string are alphanumeric (alphabet or number)
and there is at least one character, False otherwise.
Example:
t ="Hello123” then t.isalnum( ) gives True
t ="Hello 123” then t.isalnum( ) gives False
4. string.isalpha(): it gives True if the characters in
the string are alphabet only and there is at least one
character, False otherwise.
Example:
t ="Hello123” then t.isalpha( ) gives False
t = "Hello” then t.isalpha( ) gives True
Strings Functions & Methods:
5. string.isdigit(): It gives True if the characters in the
string are digits only and there should be at least one
character, False otherwise.
Example:
t ="Hello123“ then t.isalnum() gives False
t= "123” then t.isalnum() gives True
6. string.islower(): this function gives True, if all letters
in given string are lowercase, otherwise it gives False.
Example:
if t="sunday" then t.islower() gives True
if t="Sunday" then t.islower() gives False