Skip to main content
UCLA

Program In Computing

PIC 16A: Python with Applications I

About

This course covers the fundamentals of the Python programming language in lots of detail. Until 2026, students took this course after PIC 10A. From 2027 onwards, students can take this course after PIC 1 or PIC 10A.

Python is very popular because it offers thousands of packages for many tasks. Although C++ allows for more optimized code, for performance-critical tasks, Python easily connects to fast C/C++ libraries under the hood. It is the primary language for machine learning (PyTorch and TensorFlow) and data science (Pandas and NumPy). Some students prefer Python to C++ because its syntax is closer to standard English and it is higher-level language, automating tasks like memory management.

As a student in this course, you will master the details of the language, like how Python variables behave, and how Python functions and methods pass their arguments. Understanding such details thoroughly is valuable because many other coding languages behave in a similar way. You will learn how to use Python data structures like lists, tuples, sets, and dictionaries effectively. You will also learn about two of the most popular libraries for data science, NumPy and Pandas, and you will see applications to data science throughout the course, particularly on your homework assignments.

Learning Outcomes / Course Objectives / Core Competencies

Incoming students should be able to...

After successful completion of PIC 16A, students should be able to...

General Course Outline / Schedule of Lectures

The following approximate schedule details the topics that 16A instructors should teach. Except where clearly indicated, all topics should be covered. The order in which the material is taught can be changed by an instructor to suit their teaching style and their vision for the class.

Lecture 1-4

  • starting with Python
    • commenting, printing
    • ints, bools, and strings
    • lists
  • control flow
    • indentations
    • two common ways to use for loops (with and without range)
    • if, elif, else, and while
  • function basics
    • specifying a type for the parameters is not necessary
    • specifying a return type is not necessary
    • when a value is not explicitly returned, None is returned.
  • variables
    • the fact that the concept of "value" in Python is more complex than in C++: value == type + object reference
  • functions in more detail
    • the fact that functions in Python pass arguments by value, and that this amounts to "pass by object reference"
    • examples demonstrating the subtleties of this situation
  • function scope
    • the fact that a variable is local to a function call exactly when it assigned to at some point in the function definition
    • such an assignment always occurs implicitly for parameters, so parameters are local to a function call
    • errors that can arise as a consequence of not understanding how function scope behaves
  • default arguments
    • stored by the function object at the time the function is defined
    • examples when the default value references a mutable object

Lectures 5-7

  • keyword arguments
  • lambda functions
  • type, id, ==, is
  • standard data structures: lists, tuples, sets, dictionaries, comprehension
  • mutable and immutable data types

Lectures 8-11

  • classes
    • instance variables
    • class variables
    • the interaction between instance variables and class variables
    • instance methods and the role of self
  • name-mangling with two underscores (optional)
  • magic methods

Lectures 12-18

  • NumPy
    • arrays, ndim, shape, dtype
    • addition and multiplication of arrays, broadcasting
    • indexing
      • basic indexing, views and copying, slicing
      • masking, index arrays
  • Pandas
    • index and columns
    • iloc, loc, “usual” indexing, and masking
    • plotting data

Lecture 19-21

  • inheritance and simple applications of "super"
  • exceptions
    • try-except
    • raise
    • inheriting from Exception (optional)

Lectures 22-26

  • Other Python libraries. At least two of the following.
    • Image Processing using NumPy more extensively (best included as part of NumPy)
    • Graphical User Interfaces (GUIs) using PyQt5 or TkInter (best included as part of inheritance)
    • Input/Output e.g. processing CSV files or XML files (best included as part of Pandas)
    • Introduction to Machine Learning (Q-Learning is recommended)
    • Regular Expressions
    • Natural Language Processing using NLTK
    • Threading

Expected Grade Scheme and Homework Assignments

Since this is an introductory class in which students often rely on homework assignments to reinforce their lecture learning in a timely manner, PIC 16A instructors are required to assign at least five homework assignments.