Gr8-8. Python Programming_Functions
Gr8-8. Python Programming_Functions
PROGRAMMIN
G
Which
functions, is it
Events?
FUNCTIONS
OBJECTIVES
Conversion of a string to
uppercase
txt = "Hello my FRIENDS"
x = txt.upper( )
print(x)
Strip Function
Remove spaces at the beginning and at the end
of the string:
txt = " apple "
x = txt.strip()
print(len(txt))
print(len(x))
Output: 9
5
Slicing[Finding substring]
You can return a range of characters by using the slice
syntax.
Get the characters from position 2 to position 5 (not
included):
b = "Hello, World!"
print(b[2:5])
Output: 1lo
Output: ['a','a','d','g','t','y']
random module
Python has a built-in module that you can
use to make random numbers.
The random module has a set of methods:
random.randint(start, stop)
import random
print(random.randint(10, 50))
Thank
you