12/30/21, 12:05 PM 2 Basic of Python - Functions
Functions
In [1]:
a = "welcome"
In [2]:
a.capitalize()
Out[2]: 'Welcome'
In [3]:
# Dot and tab will provide you the list of functions. We can use them directly
In [3]:
b = "money"
In [4]:
b
Out[4]: 'money'
In [5]:
# It will comvert first letter of word into Captial
b = b.capitalize()
In [6]:
b
Out[6]: 'Money'
In [6]:
# it will convert word in lower case letter
b = b.lower()
In [7]:
b
Out[7]: 'money'
In [8]:
# It will convert all letters in Captial
b = b.upper()
In [9]:
b
Out[9]: 'MONEY'
In [11]:
# to Find the index of letter in word
b.find("N")
Out[11]: 2
file:///C:/Users/rgandyala/Downloads/2 Basic of Python - Functions.html 1/3
12/30/21, 12:05 PM 2 Basic of Python - Functions
In [10]:
# To check Upper case data is upper case or not
b.isupper()
Out[10]: True
In [11]:
# to Check Data is lower case or not
b.islower()
Out[11]: False
In [14]:
f="Hello World"
In [15]:
# number of times repeating
f.count("l")
Out[15]: 3
In [16]:
# replace the existing letters with new letters
f=f.replace("o","k")#old letter,new letter
In [17]:
f
Out[17]: 'Hellk Wkrld'
In [1]:
c = " welcome to Data science"
In [2]:
c.split()
Out[2]: ['welcome', 'to', 'Data', 'science']
In [13]:
a = " Hello world "
In [14]:
# Strip method remove the white space from the string
a.strip()
Out[14]: 'Hello world'
In [21]:
age = 36
test = "My name is John, and I am {}"
In [22]:
test
file:///C:/Users/rgandyala/Downloads/2 Basic of Python - Functions.html 2/3
12/30/21, 12:05 PM 2 Basic of Python - Functions
Out[22]: 'My name is John, and I am {}'
In [8]:
test.format(age)
Out[8]: 'My name is John, and I am 36'
In [ ]:
file:///C:/Users/rgandyala/Downloads/2 Basic of Python - Functions.html 3/3