Python basics refresher

ITEC 3160 Python Programming for Data Analysis,
Cengiz Günay

(License: CC BY-SA 4.0)

Prev - Introduction, Next - Object Oriented Programming

The very basics

Chapter 2.3

Chapter 2.3

  • Python history: version 2 vs 3; now popular for AI & ML
  • Whitespace, quotations, language conventions, operators
  • Control statements: blocks, if-elif-else, while
  • Modules and import

An ephemeral Python practice area (wait for it to load)

How to practice Python

Do one or more of these based on your preferences!

A crash course into Python

See Chapter 2.

See Chapter 2.

  • Zen of Python
  • Installing
  • Virtual environments
  • Whitespace
  • Modules and import
  • Functions
  • Strings

Practice functions

Work in teams, but only one person should submit. Write Python code online or in your own IDE to:

  • List everyone’s names at the top in a comment
  • Add a function that prints out a salutation message
  • Create a list and a for loop that prints out each element
  • Add an if-statement that behaves differently for some elements of the list

Add two more functions around a theme of your choice and make sure to use:

  • docstrings: show usage
  • f-strings: print or return
  • lambda functions: show a use example
  • default function parameters: show usage for provided vs missing parameters

Make it interesting!

Language basics

(Continuing DSS Chapter 2)

  • Lists
  • Tuples
  • Dictionaries (default, Counter)

Practice basics in-class exercise

Work in teams on any IDE, create a program with a theme of your choice that uses:

  • input from a user in a loop
  • a dictionary to store a list of items and their associated values
  • check if items exist in the dictionary and

In addition, make sure your program includes the following:

  • A function that returns multiple values using a tuple
  • Use list unpacking to assign variables from tuple
  • Access a list’s elements by using slicing
  • A loop that deletes from a dictionary
  • Finish by printing out the dictionary

Misc Python Oddities

(Continuing DSS Chapter 2)

  • Sets
  • Control flow
  • Truthiness
  • Sorting
  • List comprehensions
  • Zip and argument unpacking
  • Type annotations (just the basics)

Practice Misc Python Stuff

Work in teams on any IDE. Create a program that includes:

  • A set: add elements and check for membership
  • An if-elif-else statement
  • A loop with use of break and continue
  • Use truthiness of data structures in a conditional statement (other than simple binary operators), could be for loop logic
  • sort a data structure and print them out
  • create a list using the list comprehension syntax, you can use the data from the set
  • use zip somewhere
  • specify type annotations in at least one place
  • make sure it’s sufficiently distinct from others’ submissions and that your program has a theme
Home