" Python is the new Black "
Maria João Mira Paulo
Lists, Manipulating Lists, Loops.
- Dictionaries ...
Variable Types
Ready?...😎
Data type that holds an organized collection of items.
list_name = [item_1, item_2, item_N]
Objects in a list can be accessible by index. Remember that list index star by.... 0!
Example of an empty list
list_name = []
Example 🤔 list_name[index]
Create a list of animals with the values: - Camel, Fox, Horse and Panda. Now show the Fox and the Panda on the screen.
1.
(Creating lists)
Example 🤔 list_name[index]
Example 🐑 list_name[index] = 'sheep'
['cow', 'panda', 'fox']
To a list
1. To create a function, use the def keyword followed by the name of the function.
2. Always follow the function name with a set of parentheses.
3. If your function accepts parameters you may include the
names of those parameters within the parentheses, separating them with commas.
def say_hello(name):
print('Hello ' + name)
def say_hello(name = 'there'):
print('Hello ' + name)To create optional parameters,
set a default value by using the equals sign.