Get Started Programming

Best Way to Learn Python: Resources and a Brief How-To

Python is one of the fastest growing programming languages. Even though it’s been around since 1989, it’s still widely used and learned. It provides an opportunity to work with a lot of programming fields, from web development to data science to game development.

If you want to get started in Python and don’t know how, you’re in the right place. Lots of open-source materials are available for you to learn Python. In this post, I’ll share some easy-to-follow resources that will help you get started on your Python journey. After that, I’ll explain some Python basics that we’ll use to build a simple program.

Beginner Python Resources

I’ll divide the resources into three types: text, video, and interactive. I’ll be assigning a difficulty level to them. These levels are based on how convenient they are to follow and whether they are good for beginners or you should learn some Python before diving into them.

Text Resources

Let’s start by looking at three text resources that are available free to folks looking to get started with Python.

Automate the Boring Stuff (Level: Beginner)

If you ask anyone about Python resources, the one that tops the list is Automate the Boring Stuff by Al Sweigart. It’s also free to read under a Creative Commons license. It covers a variety of topics in Python while taking the reader through code examples. You’ll learn many things along the way like web scraping, data handling, file handling, image manipulation, and more. So, if you want to get going in Python and build something while doing it, Automate the Boring Stuff can be the perfect place to start.

Practical Python (Level: Intermediate)

Practical Python is also a great text-based resource that helps beginners follow and grasp the basics of Python. This book is more about going into details of Python and how to write better Python code. It will give you an idea about how to structure your Python code and how to handle data. But it also goes into some interesting details on generators, lambdas, and function decorators that will really help you move from a novice to more advanced Python programmer.

Dive Into Python3 (Level: Intermediate)

Last but not least, Dive Into Python3 is an amazing resource if you have some know-how of Python and want to take it to the next level. Dive Into Python3 goes into a bit more detail about fundamental concepts related to Python and programming without overwhelming the student.

You’ll learn about parsing XML, HTTP requests, and important topics like unit testing and refactoring that you’ll definitely come across in your professional career as a Python developer. Again, it’s also available under a Creative Commons license and is free to read on the website.

Video Resources

To start your Python journey through some video references and follow-along tutorials, you can look at Python Bite Size, Corey Schafer’s YouTube channel, and The New Boston. These are great for beginners and will help you understand a lot of Python basics.

Python Bite Size (Level: Beginner)

Python Bite Size provides a list of videos that you can follow along with to not only set up Python but also learn about its basics like program control and functions. If you’re interested in GUI programming using Python, this tutorial is a perfect platform. It gives you an introduction to Tkinter, a Python library that’s used for developing GUI-based applications. You can  follow along and build a digital clock. There’s also a section on turtle, which is Python’s library to draw simple graphics.

Corey Schafer (Level: Beginner to Intermediate)

Corey Schafer provides amazing videos on YouTube. In this playlist, he gives an introduction to Python and then talks about different Python modules. He provides insights into file handling, file parsing, and CSV parsing in Python. He also talks about unit testing and virtualenv (venv) for Python later in his playlist. So, this channel can be a detailed introduction to Python from the beginner to intermediate level.

The New Boston (Level: Beginner)

Although this is an old tutorial by The New Boston, it provides a detailed introduction to Python and will be quite helpful for beginners. This playlist goes through basics in detail and then also talks about object-oriented Python design and programming.

You’ll also get an introduction to image manipulation in Python using Pillow, which is a Python imaging library used for image manipulation. Want to learn more about image manipulation through code? The New Boston can be a good start.

Interactive Resources

Apart from the text and video resources I discussed above, there are quite a few interactive resources available for learning Python on your own. Interactive resources provide an added benefit: you don’t have to set up anything on your computer and can learn it at your own pace in the browser.

Websites like Datacamp and Dataquest are primarily for data science, but they still provide a free learning path for basic Python. PythonAnywhere is a useful resource for learning Python in your browser with an online interpreter. Trinket.io has a bunch of free resources available for learning Python and gaining basic knowledge about the language.

How to Build a Simple Program in Python

Now, we’ll go through the basic steps of setting up Python and an IDE. We’ll also look at how we can best use IDE for Python development—VS Code in this case. We’ll also go through some basics of Python and write our first program.

Let’s get started!

Setup

The first step is to go to the Python website and download the latest version of Python. Python.org provides with installation packages for all major operating systems: Windows, Linux, and MacOS.

IDE

To write code, you’ll need a text editor. It’s always better to use an IDE that provides support for your programming language of choice. VS Code is one of the best IDEs when it comes to providing Python support, and it is available for free. You can download it here.

Also, for additional Python support you can download VS Code’s Python extension.

Basic Concepts You Need to Write Your First Program

In the next section, we’ll be writing our first program. Instead of making a “Hello, World!” program, we’ll be looking at some basics of Python:

  • variables
  • conditionals (if else … else if)
  • functions
  • loops

Variables

Variables are used to hold data in Python. In Python, you don’t have to specify the data type for a variable; you can assign the variable, and interpreter will do the rest for you. Here, you can see that at runtime, the Python interpreter will determine that

  • the first and last name are strings, a data type that is used to store characters; and
  • age is an integer, a data type that is used to store numbers.
# Defining strings for name and integer for age
first_name = "Name"
last_name = "Last Name"
age = 30

Conditionals

Conditionals are used to control program flow and to add our desired outcomes in a program. In Python, conditionals can be used as

# Only people with age 18 or over are allowed to drive
if age > 18:
    print(age)
else:
    print("You are not allowed to drive")

Functions

Functions are basic building blocks of a program. They help us keep our code readable and more manageable. In Python, functions can be defined as

# A basic function that shows if a person is allowed to drive.
def is_allowed_to_drive(int age):
    if age > 18:
       print("You are allowed to drive")
    else:
       print("You are not allowed to drive")

Loops

Loops provide an iterative way to go over and do a repetitive task. In Python, there are two kinds of loops: for loops and while loops.

# Using while and for loops to print numbers from 0 to 9.
x = 0
while x != 10:
    print(x)
    x = x+1
for i in range(0, 10):
    print(i)

Time to Build Your First Program!

Now that we understand the basic concepts, let’s integrate it all into one program and write a simple function that delivers a student’s grade when provided with marks out of 100. It will take input from the user and print out the grade. It also checks if the user has entered value other than zero to 100.

You can try the code here.

# A Function that is returns grades depending on the marks obtained.
def grader(marks):
    if marks > 100 and marks < 0:
        return "Input Marks between zero and hundred"

    elif marks <=60:
        return "F"
    elif marks <=70:
        return "D"
     elif marks <=80:
        return  "C"
    elif marks <= 90:
        return "B"
    elif marks <= 100:
        return "A"
    else:
        return "Wrong Marks"
# taking input into marks variable
marks = int(input("Enter Marks"))
grade = grader(marks)
print(grade)

Conclusion

There’s a lot to learn when it comes to programming, and Python is no different. It requires dedication and hard work, but once you get the grasp of things, it becomes fun to learn and fun to play with. These resources provide a basic guideline for you to get started and get a basic foothold in the Python world. Remember, it’s a big world and there’s a lot to learn, so patience and persistence are key. Best of luck in your Python journey!