Create a string and then print the last letter of the string using negative indexing
list.extend()
list.copy()
print("Hello, Alice!") print("Hello, Bob!") print("Hello, Charlie!")
def say_hello(name): print("Hello,", name) say_hello("Alice") say_hello("Bob") say_hello("Charlie")
Question: Which version is easier to extend?
def
def greet(): print("Hello, world!")
greet
greet() greet()
Output:
Hello, world! Hello, world!
def greet(name): return "Hello " + name "!"
We can use the assert statement to test functions.
def greet(name): return "Hello " + name "!" res = greet("Bob") expected = "Hello Bob!" assert res == expected, res
What happens if you define a function but never call it?