7554425D-0054-440D-B95E-D2ABC13D62CD Created with sketchtool.
Your Saved Info Packages

View your saved Course or Program Packages containing pricing and detailed curriculum.

Speak with a Learning Advisor.

Have any questions? We'll call you.

Fill out the form below and a Learning Advisor will reach out at a time convenient for you.

Please pick a valid date and time between 9 AM and 8 PM eastern (Monday to Friday)

By clicking "Book a call," you accept our Terms and will also receive exclusive offers and updates about new courses, workshops and events.

Python Tutorial

Intro To Python Programming

Ready to start your career in Data? Find out more about BrainStation's Python Course

Before you can start programming with Python, there are a number of general programming fundamentals that are important to understand. Let’s take a closer look at the basics.

Programming Language Basics

Programming languages tend to share some foundational concepts and general building blocks. By learning these concepts, we can gain a better understanding of any new programming language that we might come across in the future.

With that being said, it is very important to have a solid understanding of the basics of programming languages before starting to write code. In most cases, only the process of writing code and executing it will change between individual languages. Let’s dive into these building blocks and first deepen our understanding of syntax and semantics:


Syntax defines a set of rules and a combination of various symbols. Syntax is followed to write properly structured code that can be accepted by the language, before it is issued as instructions for the computer to run. Programming languages can vary in the syntax used, and code is written in a document with a particular file extension (e.g. for Python language code is written in a file with a '.py' extension). If the code written is not valid syntactically, the document will show “syntax error”. We’ll explore Python syntax in the upcoming lessons.


The semantics of a language are responsible for defining the meaning behind the syntax. In other words, it’s not enough to write a sentence with the proper punctuation and grammar, and order of words if it doesn’t mean anything. For example, the sentence “The desk ate the color blue.”, is syntactically correct, but doesn’t have any meaning. The same goes for programming. While code might be written with the right syntax in mind, the end result has to mean something.

For our purposes, semantics describes a set of processes a computer will go through while executing the code in a particular language. This could be determining what output a program should produce for a given set of inputs or it could be just describing the process of how a code will be run on different platforms. Semantic analysis takes any code written and determines whether or not the code consists of valid strings. If not, the code would not be run and meaningful errors will be thrown to tell the programmer that the code contains errors.

In this lesson, we will go through a quick introduction to Python as a programming language. Note: We will be using Python 3 for programming in Python

How to Write Python Code

While Python is one of the most beginner-friendly programming languages in use, it’s a good idea to understand some core principles before getting started. Python programming courses, for example, have grown in popularity, as they can quickly get you up and running with the language.

It’s also a good idea to take advantage of the wealth of material available online. There are a number of PEP documents, for example, which can be invaluable for beginners. PEP stands for Python Enhancement Proposal, and these documents describe new features and aspects of Python, including documents, design, and style.

PEP 8 is a readily-available document that aims to improve the readability and consistency of Python code – it also provides guidelines and best practices on how to write Python code.

Expressions or Statements

An expression or a statement is a line of code or building block that is syntactically correct and is supposed to carry out a certain action when executed. In the last lesson, we typed 2 + 2 in our notebook. In this case, 2 + 2 is an expression or statement that when executed, will result in an action of performing the addition of two numbers. The outcome of the action will be the result - in this case, 4.


Indentation, also referred to as leading whitespace, is an important element of Python. The way that lines of code are indented in Python determines how statements are grouped together.

​​PEP 8 includes two key indentation rules:

  • Make sure to use four consecutive spaces to indicate indentation.
  • Use spaces instead of tabs.

Mathematical Operators

There are many mathematical operators that Python provides that are useful as part of writing code. Addition +, Subtraction -, Multiplication *, Division /, Modulus or Remainder % and Power or "Raised To" ** are some of the mathematical operators that Python provides to developers. Type the following code one line at a time and run the cell each time.

Set Password

You already have an account with BrainStation, but you still need to set up a password.