Microsoft
Course Description
This course leverages your experience as a coder in other languages to quickly get you up to speed with writing effective Python. Learn why you might want to use Python and all the foundational basics: data types, numbers, strings, lists, sets, tuples, and dictionaries. We will then cover some practical applications for those python programs, go over libraries and modules, and end the course build in the Django web framework.
This course and others like it are available as part of our Frontend Masters video subscription.
Preview
CloseWhat They're Saying
I just completed "Practical Guide to Python" by Nina on Frontend Masters! It is indeed quite practical and right to the point.

Nathaly Toledo
toledo_nathaly
Wow "Practical Guide to Python" was fun! And a lot to go though.

Mekael Turner
mekaelturner
Course Details
Published: December 22, 2020
Learning Paths
Learn Straight from the Experts Who Shape the Modern Web
Your Path to Senior Developer and Beyond
- 200+ In-depth courses
- 18 Learning Paths
- Industry Leading Experts
- Live Interactive Workshops
Table of Contents
Introduction
Section Duration: 28 minutes
- Nina Zakharenko introduces the Practical Python course and walks through the editor setup, and the prerequisites.
- Nina creates a directory and virtual environment for the Python project. The virtual environment allows a specific version of Python to be used in a project without interfering with other versions required by the operating system.
- Nina demonstrates how to use the Python REPL to run programs line-by-line. Using the REPL can be faster than using a Python file since it eliminates the hassle of running a full program. The output is instantaneous inside the REPL as each line is run.
Why Python?
Section Duration: 22 minutes
- Nina describes the history of Python, and why it appeals to a wide range of developers, from beginners to large-scale development teams at Instagram or Dropbox. Since Python is open source, there is a large community of contributors and third-party packages.
- Nina walks through a completed Python program that uses the GitHub API to load data from Python, JavaScript, and Ruby repositories with over 60000 stars. The code contains examples of variables, functions, lists, dictionaries, and loops.
- Nina answers questions about different string formatters, and how to install third-party packages like the "request" package.
Variables & Data Types
Section Duration: 42 minutes
- Nina demonstrates how to create variables in Python. Variables are dynamically typed and the recommended naming convention is all lowercase letters with underscores between words.
- Nina shares three helpful methods that can be used in the REPL. The type() method will return the type of a variable. The dir() method returns all the built-in methods for a class. The help() method returns the documentation for any class type or class method.
- Nina demonstrates the int, float, and complex number types. The Boolean values True and False cast to the int values 1 and 0.
- Nina demonstrates how to work with strings. Preceding a string with the letter "f" creates an f-string which allows variables and expressions to be added inside curly brackets. String methods like replace() return the modified string value without mutating the original string.
- Nina demonstrates the list data type. Lists can be sorted or mutated with methods like append(), insert(), and reverse().
- Nina walks the students through the data types, strings and numbers practice.
Functions, Loops, & Logic
Section Duration: 1 hour, 40 minutes
- Nina explains that tuples are light-weight collections for keeping track of related, but different items. Unlike lists, tuples are immutable.
- Nina demonstrates that sets are mutable data types that store immutable items in an unsorted way. Items can be added and removed from sets. Unlike a list or tuple, a set can only contain one instance of a unique item.
- Nina explains that dictionaries store data in key-value pairs. Dictionaries allow for fast item look up and fast membership testing because their keys are immutable.
- Nina shares some naming convention guidelines for Python files. File names should be short, all lowercase and use underscores to separate words. Python .pyc files are compiled intermediary files that can be ignored and should not be checked into source control. The pprint module is useful for printing large data structures like long lists or big dictionaries.
- Nina explains that functions are defined with the "def" keyword. Arguments are included between the parentheses of a function. The body of a function is indented after the function definition.
- Nina demonstrates boolean operators and controls statements like if, elif, and else. The "is" keyword best for checking identity between two objects, not equality. If/Else statements use a colon and indentation similar to function blocks.
- Nina walks the students through the Sets, Tuples, & Dictionaries practice.
- Nina walks the students through the Functions and Logic practice.
- Nina demonstrates "for" loops. The range() and enumerate() functions simplify the syntax when looping over large amounts of data. Tuple unpacking is useful when looping over tuples and dictionaries.
- Nina walks the students through the Loops practice.
Practical Applications
Section Duration: 24 minutes
- Nina uses a list comprehension to perform an operation on every item in a list with only one line of code. A condition can be added to the list comprehension to determine if that value should be included in the returned list. Generator expressions are also covered in this segment.
- Nina demonstrates how to use slicing to return a subset from a larger list. Slicing can be used on any data type that maintains an order, such as a string, list, or tuple.
- Nina explains how Python works with files on the operating system and the different modes available when opening a file. A context manager is a safer way to work with files since it will automatically close the file even if an exception occurs.
- Nina walks the students through the working with Files practice.
- Nina walks the students through the Practical Applications practice.
Object Oriented Python
Section Duration: 23 minutes
- Nina introduces Python classes, and explains the difference between a classes and the instance of a class. All Python data types inherit from a superclass. Within a class definition, the "self" keyword is used to reference the individual instance of that class.
- Nina uses the @classmethod annotation to define a static method on a class that's shared across all instances. Python classes also have magic methods that are defined with two underscores before and after the method name. Some examples of magic methods are __init__(), __str__(), and __repr__().
- Nina shares a brief inheritance example. If a subclass is defined in the same file as its superclass, the class definition should be below the superclass's definition.
- Nina implements exception handling with the "try" and "except" keywords. If an exception is thrown inside the "try" block, the error can be handled inside the "except" block. Multiple "except" blocks can be added to handle specific exception types.
Libraries & Modules
Section Duration: 23 minutes
- Nina recommends adding a main method to Python programs to make them more modular. The main method will only execute when the program is running as a stand-alone application. If it has been imported in another module, the main method will not run.
- Nina shares best practices around using virtual environments. A requirements.txt file is used to annotate dependencies for a virtual environment. This file can be created manually or generated automatically by Python's package manager.
- Nina explains how the import keyword is used to import either an entire module or just a function from a module. Python's standard library contains a number of useful modules for handling dates, system-specific functions, and json data.
- Nina recommends copying the "pip install" command from the Python Package Index website to ensure the correct external package is installed. The requests library loads data from an external API. The status_code property in the response object can be used to handle successful or erroneous requests.
- Nina walks the students through the Object Oriented Python practice.
- Nina walks the students through the Libraries and Modules practice.
Web Frameworks
Section Duration: 30 minutes
- Nina introduces the Django and Flask frameworks for Python. Django includes a lot of features out of the box like ORM, user authentication, and content management. Flask allows users to create basic backend APIs easily, but requires third-party packages to extend beyond this basic functionality.
- Nina installs the Django framework and uses it to create a basic blog application. The migrate command uses the manage.py file to initialize the database. The runserver command starts the local development server.
- Nina explores the Django project and the code that communicates with the SQLite database. Whenever a field is added or removed from the models in Django, the makemigrations and migrate commands should be run to update the database. The Django "shell" command allows models to be worked with in the command line.
- Nina explains how Django manages views and routes within the application. HTML templates are returned based on the pattern of the URL. Class-based views are also discussed in this segment.
- Nina uses the Django admin interface to manage the content of the blog. The admin can also manage user authentication and permissions.
- Nina explains why unit tests in Django should inherit from the TestCase class and not the built-in unit test package in Python. This segment also covers the final project practice which involves sorting blog posts and adding an is_draft field.
Wrapping Up
Section Duration: 1 minute
- Nina wraps up the course by sharing some additional Python resources, more information about Python frameworks, and how to connect with the Python development community.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops