In-Built function syntax and example
Definition and Usage
The capitalize() method returns a string where the first character is upper case.
Syntax
string.capitalize()
Upper case the first letter in this sentence:
txt = "hello, and welcome to my world."
x = txt.capitalize()
print (x)
OUTPUT :Hello, and welcome to my world.
Definition and Usage
The count() method returns the number of times a specified value appears in the
string.
Syntax
string.count(value, start, end)
Parameter Values
Parameter Description
value Required. A String. The string to value to search for
start Optional. An Integer. The position to start the search. Default is 0
end Optional. An Integer. The position to end the search. Default is the end of the string
Return the number of times the value "apple" appears in the string:
txt = "I love apples, apple are my favorite fruit"
x = txt.count("apple")
print(x)
OUTPUT:2
More Examples
Example
Search from position 10 to 24:
txt = "I love apples, apple are my favorite fruit"
x = txt.count("apple", 10, 24)
print(x) OUTPUT:1
Definition and Usage
The islower() method returns True if all the characters are in lower case, otherwise
False.
Numbers, symbols and spaces are not checked, only alphabet characters.
Syntax
string.islower()
Parameter Values
No parameters.
Example :Check if all the characters in the text are in lower case:
txt = "hello world!"
x = txt.islower()
print(x)
OUTPUT:TRUE
Example:Check if all the characters in the texts are in lower case:
a = "Hello world!"
b = "hello 123"
c = "mynameisPeter"
print(a.islower())
print(b.islower())
print(c.islower())
output: False
true
false
Definition and Usage
The join() method takes all items in an iterable and joins them into one string.
A string must be specified as the separator.
Syntax
string.join(iterable)
Parameter Values
Parameter Description
iterable Required. Any iterable object where all the returned values are strings
Example
Join all items in a tuple into a string, using a hash character as separator:
myTuple = ("John", "Peter", "Vicky")
x = "#".join(myTuple)
print(x )
output:John#Peter#Vicky
Example :Join all items in a dictionary into a string, using a the word "TEST" as
separator:
myDict = {"name": "John", "country": "Norway"}
mySeparator = "TEST"
x = mySeparator.join(myDict)
print(x)
OUTPUT :nameTESTcountry
Definition and Usage
The lstrip() method removes any leading characters (space is the default leading
character to remove)
Syntax
string.lstrip(characters)
Parameter Values
Parameter Description
characters Optional. A set of characters to remove as leading characters
Example
Remove spaces to the left of the string:
txt = " banana "
x = txt.lstrip()
print("of all fruits", x, "is my favorite")
output:of all fruits banana is my favorite
Example: Remove the leading characters:
txt = ",,,,,ssaaww.....banana"
x = txt.lstrip(",.asw")
print(x)
output:banana
Definition and Usage
The upper() method returns a string where all characters are in upper case.
Symbols and Numbers are ignored.
Syntax
string.upper()
Parameter Values
No parameters
Example
Upper case the string:
txt = "Hello my friends"
x = txt.upper()
print(x)
OUTPUT:HELLO MY FRIENDS