Back to Module 2

Functions

Functions do something with a value and often return a result.

Function What it does Example
print(x) shows a value print("Hi")
len(x) returns length len("abc") gives 3
str(x) converts to string str(16) gives "16"
int(x) converts to integer int(3.9) gives 3
float(x) converts to float float("2.5") gives 2.5
word = "banana"

print(word)
print(len(word))
print(str(123))
print(int(4.8))
print(float("7.2"))

Practice

sentence = "I like studying Python"

print(len(sentence))
print(str(42))

Next: Methods