Intro Python 2
Intro Python 2
Recap
• Variables
• Types
• Arithmetic operators
• Boolean logic
• Strings
• Printing
• Exercises
Agenda
• Lists
• Dictionaries
• Sets
• If Else
• Loops
• Functions
• Classes
• Exercises
Lists
• One of the most useful concepts
• Group multiple variables together (a kind of container!)
Indexing a list
• Indexing – accessing items within a data structure
Comma separated
Curly brackets
Dictionary properties
• Values are mapped to a key
• Values are accessed by their key
• Key are unique and are immutable
• Values cannot exist without a key
Dictionaries
Let us define the one from the previous image
Accessing a dictionary
Values are accessed by their keys (just like a dictionary)
Conditional statement
Executed if answer is True
• elif = else + if which means that the previous statements must be false
for the current one to evaluate to true
Bitcoin broker example
Quick quiz
• What would happen if both conditions are True?
For loop
• Allows us to iterate over a set amount of variables within a data
structure. During that we can manipulate each item however we want
• What if we have much more than 4 items in the list, say, 1000?
For example
• Now with a for loop