Mode Analytics: Python Tutorial (1)

To begin my adventure into understanding Python, I decided to start off with several tutorials created by Mode Analytics. Nine lessons are provided for Python novices that utilize Mode Python Notebooks. Notebooks are available online and make it easy to begin programming without downloading additional software, like IDEs. To follow along, the Mode Python tutorial can be accessed here. Lesson 1 covers lists, dictionaries, and booleans. Below is a quick summary:

Lists: Lists are objects that contain other objects. Objects in lists stay in the same order and begin at [0].

Dictionaries: Dictionaries pair a set of objects (keys) to another set of objects (values) to form unordered key-value pairs. Keys are unique and therefore can only correspond with one object.

Booleans: Named after British mathematician George Boole, Boolean is a data type that can be stored as either True or False. Boolean expressions can be used to compare values.

Below is my code for lesson 1.

# Python Notebook - Mode Tutorial: Lesson 1

# Variables
first_string = 'this is a string'

# Lists
cities = ['Tokyo', 'Los Angeles', 'New York', 'Toronto']

# Accessing list items (beginning at 0)

# Practice problem: Get the third city in the list cities.

# Dictionaries
city_pop = {'Tokyo': 13350000,
    'Los Angeles': 18550000,
    'New York City': 8400000,
    'Toronto': 2809000,
city_pop #prints alphabetically, not in same order like lists

city_pop['Toronto'] #print population of Toronto

# Practice problem: Get the population of Tokyo

# Changing values
city_pop['New York City']= 8600000 # updated population as of 2018
city_pop # updated value now included

city_pop['Mumbai']=11980000 # Add to dictionary
city_pop # Mumbai now added to dictionary

# Combining objects
regions = {
    'New York City': [
        'The Bronx',
        'Staten Island'
    'Toronto': [
        'City of Toronto',
regions['Toronto'] # print regions in Toronto
regions['Toronto'][2] # print 3rd region in Toronto

# Practice problem: print 4th region in NYC
regions['New York City'][3]

# Boolean objects 
type(True) # type() can be used to check data type
type (regions['Toronto']) # Regions in Toronto are stored as a list

# Comparing values using Booleans
city_pop['Toronto'] == 5000 # Equal symbol, False statement
city_pop['Toronto'] > 5000 # True statement
city_pop['Toronto'] != 5000 # Not equal symbol, True statement



One thought on “Mode Analytics: Python Tutorial (1)

  1. Pingback: Mode Analytics: Python Tutorial (6) | DATADOLL

Comments are closed.