" Python is the new Black "
Maria João Mira Paulo
Lists, Manipulating Lists, Loops.

Python - Module 4

- String
- Integer
- Float

- Boolean
- List

- Dictionaries ...

 
 
Variable Types

Recapping 

Ready?...😎

Focusing on... Lists and list manipulation.

Lists

Data type that holds an organized collection of items.

- The values or items contained in the list can be various data types themselves.

- Lists are created using comma to separate values and between square brackets.

 

Creating Lists

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]

Exercise

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)

To remember...

Example 🤔 list_name[index]

- You can access values by index.

 

- You can set/modify values by index.

 

Example 🐑 list_name[index] = 'sheep'

- You can also access items by using a negative index.

['cow', 'panda', 'fox']

-3

-2

-1

Adding elements 

To a list

- The values or items contained in the list can be various data types themselves.

- Lists are created using comma to separate values and between square brackets.

 

Functions

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. 

Python - Module 4

By Maria João Mira Paulo

Python - Module 4

  • 329