Coding 101: Learn Python

In today's Coding 101 lesson we're going over the basic principles of Python to understand before you start writing Python code. This includes syntax, variable types, libraries, and the general capabilities of this language.
Share on linkedin
Share on twitter
Share on facebook

Today we’re covering the absolute basics of Python programming. If you’ve never coded in Python before – or in any other language for that matter – we’ll get you caught up with the key concepts and vocabulary that you need to start learning Python today

Ready to get started? Read on below!

What Can Python Do?

Entry-level Python is great for handling numbers and calculating many different variables. It can also be used for manipulating strings of text and establishing logical concepts like If-Then conditionals and True-False statements.

With more advanced Python skills, programmers can use this language to build web applications, automate processes, and take on large-scale data science projects.

Variables in Python

One of the first concepts to understand in Python is variables. If you learned algebra in high school you’ll be familiar with the concept. A variable is a specific word, or words, that stores a value. In Python, variables are written in all lowercase and use underscores instead of spaces.

To create a new variable, coders simply type the variable name, followed by the = symbol, and then the value stored in the variable. Here are a few examples:

  • address = 4367
  • number_of_students = 64
  • person_a = “Sam”
  • Person_b = “Ella Thompson”

Unlike in algebra, Python variables can hold values that aren’t numbers. We’ll explain the main types of variables later on.

Python Syntax

Syntax is kind of like grammar for coding. It is made up of the rules and norms for writing proper and functional code. Each coding language has its own syntax, though there is often overlap among them. 

In Python, the basic rules of proper syntax are:

  • Use indentation to separate blocks of code.
  • All variables begin with a lowercase letter. 
  • Statements are written in single lines of code. If they need to wrap to another line, you must enter a \ symbol before the line break. 
  • Use spaces around binary arithmetic operators (like + , – , / , *).

Unlike earlier programming languages Python does not use curly braces { } to contain functions. It also does not require statements to end with a semicolon, though this is allowed if the coder prefers this style.

Writing Python with proper syntax is important so that the machine you are coding on can properly execute your code. Standard syntax rules also allow programmers to easily read each other’s code.

Writing Comments in Python

Let’s say you are coding a program and you want to remind yourself to use the = symbol when defining a variable. If you were to simply write the following:

Use = to define variables

The computer would interpret this as code and try to execute it. To indicate that something is just a comment and should not be executed by the computer, begin the line with the # symbol. For example:

# Use = to define variables

Adding comments is a good way to keep track of what each block of code is supposed to do or to mark places you’d like to return to later. 

Types of Python Variables

Now that we’ve covered what variables are and how they are created, let’s list out the most common types of variables used by beginner Python programmers. These are integers, floats, strings and booleans. We’ll explain each one below.

  • Integer – A whole number, such as 3 or 1,876.
  • Float – A number with a decimal point, such as 4.87 or 8.0.
  • String – Text, otherwise known as an array of characters. Strings are written in quotations like “Hello, world.”
  • Boolean – True or false. This type of variable can only be equal to one of two values – true or false. 

Operators in Python

Operators can be used on variables to manipulate them or to create new variables by combining them. You may be familiar with arithmetic operators like + and -. Arithmetic operators also exist in Python but some of them must be written in a special way. The arithmetic operators in Python are:

  • + to add variables together
  • – to subtract one variable from another
  • * to multiply variables
  • / to divide one variable by another
  • % to find the remainder when dividing one variable by another
  • ** for exponents
  • // for floor division, which returns the largest whole number resulting when dividing one variable by another

There are a few other types of operators in Python, such as assignment operators, used to set the values of variables. The basic assignment operator is the = symbol. Other assignment operators can be used to alter the value of a variable. For example, to add 6 to a variable’s current value you can use the assignment operator += like this: x +=6. Other assignment variables include:

  • -=
  • *=
  • /=
  • %=
  • //=
  • **=
  • +=
  • =

Comparison operators are used to indicate that values are greater than, less than, or equal to one another. These operators are similar to those used in traditional math and are written as:

  • == means “equal”
  • != means “not equal”
  • > means “greater than”
  • < means “less than”
  • >= means “greater than or equal to”
  • >= means “less than or equal to”

A fourth type of basic operator is logic operators. These are AND, OR, and NOT. These operators are used to combine multiple statements. These are usually used to compute Boolean results (True or False). Here are some examples of these three logic operators:

  • x < 7 AND :x >4
  • a <= 15 OR b > 210
  • NOT x > 8

Libraries and Modules for Python

While basic operators and data types are extremely useful building blocks for Python projects, you’ll need more advanced methods and data types to build full web applications or establish complex automations. This is where libraries and modules come in. 

Libraries are extensions to Python that contain modules, or pre-written blocks of code, for specific types of coding projects. For example, if you are working with scientific data in Python, you can import the library SciPy, which contains modules of code that are useful for scientific data analysis. 

Popular libraries for Python programming include:

  • SciPy – for working with scientific data
  • NumPy – for advanced mathematical calculations
  • PyTorch – for deep learning
  • Scikit-learn – for machine learning
  • TensorFlow – for machine learning and neural networks
  • Seaborn – for data visualization
  • Matplotlib – for data visualization
  • Pandas – for data cleaning and structuring

Python FAQs

Below we’ll answer some of the most frequently asked questions about learning Python.


How do I Install Python?

You should find installing Python on any computer to be a relatively easy process. First, you might want to check if your computer already comes with a pre-loaded version of the software by entering “python” in a command line window. If you don’t see what you’re looking for, you’ll simply need to download and install the latest version of Python from the official website. Be sure to select the operating system you’re using (Windows, Linux/UNIX, macOS or other) and the most up-to-date version of the software (3.10.2 as of this writing) and you should be off to the races!

As a beginner, another option is to download and run Python in an Integrated Development Environment (IDE), which is a type of software for building applications that consolidates developer tools. IDE’s like Thonny are created with new programmers in mind and provide intuitive features like an interface stripped of all but essential features, code hinting, syntax error highlighting. IDEs like Thonny come bundled with the latest version of Python and don’t require a separate installation. 


Is Python Object-Oriented?

Python supports object-oriented programming, in which concepts are defined as objects and programs are written using inheritance, encapsulation, polymorphism, and data abstraction. However, some programmers do not consider Python to be strictly object-oriented by the most narrow definition of object-oriented programming. This is because it does not allow for strong encapsulation. Strong encapsulation hides some of the process behind a class that is implemented. The creator of Python, Guido van Rossum, did not believe in hiding how classes work.


What Basic Python Skills Should I Learn First?

Python syntax is very similar to basic English, which means you should find the code base comprehensible and intuitive. However, this doesn’t mean you can skip past the basics. We recommend beginners start by ensuring they have a firm grasp of Python vocabulary, including variables, data types, index and script. In your first projects, you’ll put these elements into practice and begin to understand how they work within the context of building a program. 

When it comes to core concepts, a developer should start by gaining familiarity and expertise in:

  • Data structures
  • File handling
  • Exception handling
  • Web frameworks, like Django or Flask
  • Object relational mappers 

The best way to master these is by seeking out books, tutorials, blogs and courses written with the total beginner in mind. We’ll dive into where to find some of the most authoritative and trusted learning materials and resources in the section below. 


Where Can I Practice Python Programming?

There are endless options when it comes to finding resources to gain hands-on experience with Python programming. Our recommendation is to take some time to explore the style of information delivery that works best for you. For some, that might mean a guided interactive course, while others would rather take  in information on their own terms via blogs or printed books. If you’re a casual learner you might find your interest peaked by one of the many gamified learn python websites where more intense enthusiasts might be drawn to an academic-style course. Regardless, the official Python Wiki “Python for Non-Programmers” guide is a great place to start to find all these types of resources and more. In addition, here’s a list of some of our personal favorites sourced from all over the web.

  • Dataquest.io – Multiple Python courses broken out by focus (Data Science, Data Analyst etc.) and level of expertise
  • TwilioQuest – A free adventure game that’s solved using Python basics. Updated regularly
  • CS for All – An open-sourced online book from professors at Harvey Mudd College. 
  • HackInScience – A free and interactive Python Exercise platform. Write code and get instant feedback from their “correction bot”
  • LearnPython.org – Another site chock full of interactive tutorials designed with beginners in mind. 
  • CheckiO – “Expanding the world’s code literacy through game play” is this site’s mission. Complete a series of fun fantasy challenges while improving your Python skills.
  • A Byte of Python – A combination book/online blog, this site breaks down common Python issues into the order in which a user might encounter them starting with installation, first steps and basics. 
  • Google’s Python Class – The free course from the search giant covers key topics using videos, written materials and practice exercises. 
  • Programiz Learn Python – On the go? Then this mobile app for iOS and Android might be your solution of choice, as guided lessons and practical examples help you learn at your own pace right from your phone. 
  • Python.Land – Beginner’s Tutorial – As implied by the name, this tutorial is easy to read and practical, with an emphasis on “getting stuff done in the real world” prioritized over theory. 
  • ItsMyCode.com – A blog for learning beginner and advanced concepts in Python, Data Science and Machine Learning
  • FreeCodeCamp – One of the most established players in the coding world, more than 40,000 graduates have earned free certificates from completing their programs. They also offer a searchable database of more than 8,000 individual tutorials. 
  • Edabit – Complete their interactive tutorial, then compete in hundreds of fun yet complex challenges ranging from “very easy” to “expert.” The site even offers a “shuffle” feature that generates a random unsolved challenge to complete. 
  • Finxter – This site offers more than 300 solvable puzzles to test and train your Python skills, as well as a blog with expert tutorials. 
  • Hackr.io Python – Hackr.io is one of the most popular online coding communities, so you can trust this list of Python tutorials generated by user upvotes. 


Where Can I Find Python Practice Projects?

After learning the basics, the next step in most coders journeys is to start creating your own projects. Once again, we can turn to the internet to generate an endless amount of ideas and inspiration aimed at everyone from total newbie to absolute expert. On the beginner side, you’ll likely start by programming simple games like Tic-Tac-Toe or Rock, Paper, Scissors, then move into practical task automation such as a GIF creator or image downloader. Here are just a few of the many project idea compilations you can use to get started. 


Which Python Libraries Should I Use?

The answer to the first question is a definite yes! The answer to the second question needs a little more context. First of all, when it comes to programming languages, a library refers to a collection of precompiled codes used for a specific well-defined operation. These bundles of code come in the form of modules that can be used repeatedly in different operations. Essentially, libraries make programming simpler and more convenient, as using them means you don’t have to rewrite already available code over and over again. Linking a library to your Python program allows you to search for specific functionalities and insert them into your programming. 

When it comes to which libraries you need to know, the answer depends on how you intend on using your Python programming knowledge. Libraries are developed to assist those working in specific areas, such as Machine Learning, Data Science or Data Visualization. If you intend on just using Python as a hobby, you might not need to take a deep dive into the world of libraries, but if you’re interested in entering a specific field, it’s worthwhile to familiarize yourself with the relevant ones. Below, we’ve listed out the most popular open-source libraries and their use cases. We recommend seeking out tutorials and guides that align with your own area(s) of interest!

  • Matplotlib – Used for plotting numerical data and creating charts and graphs like histograms and pie charts. Widely used in the Data Analysis field. 
  • Pandas – An open sourced machine learning library with analysis tools for data cleaning, manipulation, conversion, visualization and more. Used by Data Scientists 
  • Numpy – Short for “Numerical Python,” Numpy is used for handling large matrices and multi-dimensional data. 
  • PyGame – For game developers and graphic artists, this library provides an easy interface to the Standard Directmedia Library (SDL) of open-sourced graphic and audio inputs. 
  • Scikit – learn – A Widely used library in the machine learning world used for functions like regression, clustering and model selection


How Long Does it Take to Learn Python?

Well, how much time do you have to devote to studying and practicing? In General, it can take around two to six months to learn the fundamentals of Python, but you can definitely master the basics in 30 days or less! 

As we’ve mentioned above, Python is truly the perfect starter programming language: it’s extremely popular, easy to understand and comes with a worldwide support network. Plus, you can up your earning potential greatly by entering one of the many fields that require skilled Python programmers. 

Ultimately, the time it takes you to learn Python will depend on your chosen learning path. If you read a chapter a day of a book, or set aside an hour or two for practical practice, expect to become an expert at a slow but steady pace. On the other hand, enrolling in a coding bootcamp might take up your entire day, but you’ll find you’re well on the way to becoming a coding professional in just a matter of months or even weeks. 


What Coding Language Should I Learn Next?

Within a few months, as you level up from beginner to indeterminate to expert, you might start to wonder what moves you should make next with your newfound programming knowledge. One option is to start exploring careers to pursue as a programmer, which could include Web Developer, Data Scientist or Software Engineer. Having a career path in mind can be a helpful guide as you tailor your education towards the most relevant advanced skills and libraries.

Once you’ve mastered one programming language, the next ones come even easier, which is why many round out their programming education by adding one comprehension in additional languages. Following Python, look towards mastering  HTML/CSS, Java and R as potential next steps. You might even want to consider complementary skills and platforms, such as Tableau, Excel and Financial Modeling.


Wherever your coding journey takes you, we wish you the best of luck and encourage you to explore our resources right here on codingbootcamps.io! 

Related Articles