You are on page 1of 5

Inbuilt Functions:

These are the functions,whose task is predefined by the developer. When ever we
want we can utilize in our
program but we can not modify the special meaning of thses functions.

Inbuilt functions on STRING:


----------------------------------------
1.upper()
Converts a string into upper case.
syntax:
var.upper()
example:
a='hai'
a.upper()
==>'HAI'

2.lower()
Converts a string into lower case.
syntax:
var.lower()
example:
a='HaI HoW'
a.lower()
==>'hai hello'

3.isupper()
Returns True if all characters in the string are upper case.
syntax:
var.isupper()
example:
a='HAI'
a.isupper()
==>True
'Hai'.isupper()
==>False

4.islower()
Returns True if all characters in the string are lower case.
syntax:
var.islower()
example:
a='hai'
a.islower()
==>True
'Hai'.islower()
==>False

5.isalpha()
Returns True if all characters in the string are in the alphabet.
syntax:
var.isalpha()
example:
a='haiHEllO'
a.isalpha()
==>True
a='Hai 12hello'
a.isalpha()
==>False
6.isnumeric()
Returns True if all characters in the string are numeric.
syntax:
var.isnumeric()
example:
a='123'
a.isnumeric()
==>True
a='hai123'
a.isnumeric()
==>False

7.isalnum()
Returns True if all characters in the string are alphanumeric.
syntax:
var.isalnum()
example:
a='hai123'
a.isalnum()
==>True
a='hai'
a.isalnum()
==>True
a='123'
a.isalnum()
==>True
a='hai@12'
a.isalnum()
==>False

8.capitalize()
Converts the first character to upper case.
syntax:
var.capitalize()
example:
a='hai hello'
a.capitalize()
==>'Hai hello'

9.istitle()
Returns True if the string follows the rules of a title.(i.e the first
cahracter of each and every word
should be in capital letter)
syntax:
var.istitle()
example:
a='Hai Hello How Are You'
a.istitle()
==>True
a='hai Hello'
a.istitle()
==>False

10.title()
Converts the first character of each word to upper case.
syntax:
var.title()
example:
a='hai hello how are you'
a.title()
==>'Hai Hello How Are You'

11.isspace()
Returns True if all characters in the string are whitespaces.
syntax:
var.isspace()
example:
a='hai '
a.isspace()
==>False
a=' '
a.isspace()
==>False

12.startswith()
Returns true if the string starts with the specified value.
syntax:
var.startswith()
example:
a='hai hello'
a.startswith('h')
==>True
a.startswith('hai')
==>True
a.startswith('y')
==>False

13.endswith()
Returns true if the string ends with the specified value.
syntax:
var.endswith()
example:
a='hai hello'
a.endswith('o')
==>True
a.endswith('hello')
==>True
a.endswith('m')
==>False

14.count()
Returns the number of times a specified value occurs in a string.
syntax:
var.count('substr/char')
var.count('substr/char',SI)
var.count('substr/char',SI,EI+/-1)
example:
a='hai hello how'
a.count('l')
==>2
a.count('hai')
==>1
a.count('h',2)
==>2
a.count('h',2,6)
==>1

15.index()
Searches the string for a specified value and returns the initial position of
where it was found.
If the value is not present it will through an error.
syntax:
var.index('substr/char')
var.index('substr/char',SI)
var.index('substr/char',SI,EI+/-1)
example:
a='hai hello how'
a.index('o')
==>8
a.index('y')
==>ERROR---
a.index('h',2)
==>4
a.index('h',5,12)
==>10

16.find()
Searches the string for a specified value and returns the initial position of
where it was found.
this function is exactly same as index() but if the element is not present
then, it will not through any error
instead it will return -1
syntax:
var.find('substr/char')
var.find('substr/char',SI)
var.find('substr/char',SI,EI+/-1)
example:
a='hai hello how'
a.find('o')
==>8
a.find('y')
==>-1
a.find('h',2)
==>4
a.find('h',5,12)
==>10

17.rfind()
Searches the string for a specified value and returns the last position of
where it was found.
syntax:
var.find('substr/char')
var.find('substr/char',SI)
var.find('substr/char',SI,EI+/-1)
example:
a='hai hello how are you'
a.rfind('o')
==>19

18.split()
Splits the string at the specified separator, and returns a list. If we don't
specify any cahracter
at that time splits the string where ever we have ' '.
var.split('sub/char')
var.split('sub/char',no_of_splits)
example:
a='hai hello how are you'
a.split()#it will split by ' '
==>['hai','hello','how','are','you']
a.split('o')
==>['hai hell','h','w are y','u']
a.split('a',1)
==>['h','i hello how are you']

19.join()
Joins the elements of an iterable to the end of the string with the help of
gluestring.
syntax:
gluestr.join(var)
example:
a=['hai','hello','how']
' '.join(a)
==>'hai hello how'
'@'.join(a)
==>'hai@hello@how'

20.replace()
Returns a string where a specified value is replaced with a specified value.
syntax:
var.replace(oldstr,newstr)
example:
a='i like banana and my freind also likes banana'
a.replace('banana','apple')
==>'i like apple and my freind also likes apple'

Note:
We can't modify the orginal string value by using inbuilt functions ,but we can
modify and store the result in
res variable and we can utilize it for future purpose'

You might also like