Tutorial Series

How To Code in Python 3

Python is an extremely readable and versatile programming language. With a name inspired by the British comedy group Monty Python, it was an important foundational goal of the Python development team to make the language fun to use. Written in a relatively straightforward style with immediate feedback on errors, Python has a lot to offer as a programming language.
  • Python is an extremely readable and versatile programming language. While Python 2.7 and Python 3 share many similar capabilities, they should not be thought of as entirely interchangeable. This article will take you through the key differences to consider when choosing on whether to work in Python 2 or Python 3 for your development projects.
  • This tutorial will get you up and running with a local Python 3 programming environment in Ubuntu 16.04. Python is a versatile programming language that can be used for many different projects. First published in 1991 with a name inspired by the British comedy group Monty Python, the development team wanted to make Python a language that was fun to use.
  • This tutorial will get you up and running with a Python 3 programming environment on either an Ubuntu 16.04 or Debian 8 server. You'll be guided through installing Python 3 on a Linux server and setting up a programming environment. This tutorial will explicitly cover the installation procedures for Ubuntu 16.04 and Debian 8, but the general principles apply to any other distribution of Debian Linux.
  • This tutorial will walk you through writing a “Hello, World” program in Python 3. Serving as a simple and complete first program for beginners, as well as a good program to test systems and programming environments, “Hello, World!” illustrates the basic syntax of programming languages. The “Hello, World!” program is a classic tradition in computer programming. print("Hello, World!")
  • This tutorial will go over how to work with the Python interactive console and leverage it as a programming tool. Providing access to all of Python’s built-in functions and any installed modules, command history, and auto-completion, the interactive console offers the opportunity to explore Python and the ability to paste code into programming files when you are ready.
  • Comments in Python begin with a hash mark (#) and whitespace character and continue to the end of the line. Generally, comments will look something like this: # This is a comment
  • In this tutorial, we will go over the important data types native to Python: integer, float, Boolean, string, list, tuple, and dictionary.
  • This Python tutorial will go over the basics of working with strings, including how to create and print strings, concatenate and replicate strings, and store strings in variables.
  • September 15, 2016
    In this tutorial, we’ll go over some of the ways we can work with Python strings to make sure that all output text is formatted correctly. Quotes, apostrophes, multiple lines, escape characters, and raw strings will be covered.
  • Python has several built-in functions associated with the string data type. These functions let us easily modify and manipulate strings. We can think of functions as being actions that we perform on elements of our code. Built-in functions are those that are defined in the Python...
  • The Python string data type is a sequence made up of one or more individual characters that could consist of letters, numbers, whitespace characters, or symbols. Because a string is a sequence, it can be accessed in the same ways that other sequence-based data types are,...
  • This Python 3 tutorial will guide you through converting data types including numbers, strings, tuples and lists, as well as provide examples to help familiarize yourself with different use cases.
  • This tutorial will cover some variable basics and how to best use them within the Python 3 programs you create. We'll go through naming rules and conventions, reassigning variables, multiple assignment, and making local and global variables.
  • This tutorial will guide you through some of the common uses of string formatters in Python, which can help make your code and program more readable and user friendly.
  • This tutorial will go over operators that can be used with number data types in Python.
  • This tutorial will go through a few of the built-in functions that can be used with numeric data types in Python 3. Becoming familiar with these methods can give you more flexibility when programming. We’ll go over the following functions: abs() for absolute value, divmod() to find a quotient and remainder simultaneously, pow() to raise a number to a certain power, round() to round a number to a certain decimal point, sum() to calculate the sum of the items in an iterable data type.
  • The Boolean data type can be one of two values, either True or False. We use Booleans in programming to make comparisons and to control the flow of the program. Booleans represent the truth values that are associated with the logic branch of mathematics, which...
  • This tutorial will go through some of the ways that we can work with lists in Python. Lists are great to use when you want to work with many related values. They enable you to keep data together that belongs together, condense your code, and perform the same methods and operations on multiple values at once. When thinking about Python lists and other data structures that are types of collections, it is useful to consider all the different collections you have on your computer.
  • In this tutorial, we’ll go through the built-in methods that you can use to work with the list data structure in Python. We’ll go through adding items to and removing items from lists, extending lists, reversing and sorting lists, and more.
  • List comprehensions offer a succinct way to create lists based on existing lists. When using list comprehensions, lists can be built by leveraging any...
  • A tuple is a data structure that is an immutable, or unchangeable, ordered sequence of elements. Because tuples are immutable, their values cannot be modified. Tuples are used for grouping data. Each element or value that is inside of a tuple is called an item.
  • The dictionary is Python’s built-in mapping type. Dictionaries map keys to values and key-value pairs provide a useful way to store data in Python. Typically used to hold data that are related, such as the information contained in an ID or a user profile,...
  • This tutorial will walk you through installing modules, importing modules, and aliasing modules. Modules are Python .py files that consist of Python code. They can create function definitions and statements that you can reference in other Python .py files or via the Python command line interpreter. In Python, modules are accessed by using the import statement, which tells the current program to bring in the definitions and statements of the other relevant file(s) for its own use.
  • This tutorial will guide you through writing Python modules for you or others to use within your program files.
  • This tutorial will take you through writing conditional statements in the Python programming language.
  • A while loop implements the repeated execution of code based on a given Boolean condition. The code that is in a *while* block will execute as long as the *while* statement evaluates to True.
  • Using loops in computer programming allow us to automate and repeat similar tasks multiple times. In this tutorial, we’ll be covering Python’s for loop. A for loop implements the repeated execution of code based on a loop counter or loop variable. This means that for loops are used...
  • The break, continue, and pass statements in Python will allow you to use for loops and while loops more effectively in your code.
  • A function is a block of instructions that performs an action and, once defined, can be reused. Functions make code more modular, allowing you to use the same code over and over again. Python has a number of built-in functions that you may be familiar with,...
  • In function definitions, parameters are named entities that specify an...
  • In this tutorial, we’ll go through creating classes, instantiating objects, initializing attributes with the constructor method, and working with more than one object of the same class.
  • Object-oriented programming allows for variables to be used at the class level or...
  • This tutorial will go through some of the major aspects of inheritance in Python, including how parent classes and child classes work, how to override methods and attributes, how to use the super() function, and how to make use of multiple inheritance.
  • Polymorphism allows for flexibility and loose coupling so that code can be extended and easily maintained over time. This tutorial will go through applying polymorphism to classes in Python.
  • In software development, debugging is the process of looking for and then resolving issues that prevent the computer software from running correctly. The Python debugger `pdb` provides a debugging environment for Python programs. It supports setting conditional breakpoints, stepping through the source code one line at a time, stack inspection, and more.
  • Debugging is a part of the software development process where programmers look for and then resolve issues that prevent the software from running correctly. A useful and quick tool for debugging is the Python code module...
  • The logging module is part of the standard Python library and provides tracking for events that occur while software runs. You can add logging calls to your code to indicate what events have happened. The logging module allows for both diagnostic logging that records...
  • This tutorial will guide you through best practices and considerations to make when migrating code from Python 2 to Python 3, and whether you should maintain code that is compatible with both versions.