19
loading...
This website collects cookies to deliver better user experience
print() | range() | input() | list() |
next() | round() | max() | tuple() |
str() | dic() | sorted() | type() |
object() | sum() | set() | eval() |
def greet():
print("Hello World")
greet() # Hello World
def greet(name):
print( "Hello" +" "+ name)
greet("John") # Hello John
def greet(name , place):
print( f" Hello {name} from {place}")
greet( John, Uganda) # Hello John from Uganda
greet(Uganda, John) # Hello Uganda from John
greet(place ="Uganda", name="John") # Hello John from Uganda
def greet(name, place):
print("Hello" + " " + name +" "+ place)
greet("Jack", "Ghana") # Hello Jack from Ghana
greet("Jack")
Traceback (most recent call last):
File "demo_function_args_error.py", line 4, in <module>
greet("Jack")
TypeError: greet() missing 1 required positional argument: 'place'
def people(country = "Kenya"):
print("I am from " + country)
people("Sweden")
people("Burundi")
people("Ghana")
people("Nigeria")
def sum(x):
return 4 + x
print(sum(1)) # 5
print(sum(3)) # 7
print(sum(10)) # 14