Python for Beginners

Python is a programming language with many features that make it a great choice for beginners. Python’s simple, easy to read syntax emphasizes readability and therefore reduces the cost of program maintenance makes it extremely easy to read and write.

Python is a popular language for learning to code in schools, scientific computing, artificial intelligence, and more. In this article, we will explore the basics of Python programming and how you can get started with coding in Python as a beginner.

What Is Python?

Python is an increasingly popular programming language (largely because the language is fairly easy to get started with but still extremly powerful).

The language is used in everything from simple applications for learning to program to advanced machine learning applications.

Where Does the Name Python Come From?

The name does not come from the python snake but from the british comedy group Monty Python.

Who Uses Python?

Python is used in many companies, for example:

  • Netflix
  • Reddit
  • Instagram
  • Amazon
  • Facebook
  • IBM
  • Pinterest
  • Google
  • Quora
  • Spotify
  • Dropbox

Previous Knowledge

No prior knowledge is needed to start programming in Python, but it helps a little if you already know basic programming and web development with HTML, CSS and JavaScript before starting with Python.

Get Started With Python

To get started with Python, you must first install the programming language on your computer.

Install Python

Download Python: https://www.python.org/downloads/

Tutorial for installing Python on windows:

Install Python on mac:

Install a Editor/IDE for Python

An IDE, Integrated Development Environment (an: Integrated Development Environment), is an application that contains a text editor, compiler, debugger and a number of other functions that facilitate programming and testing.

There are many good editors/IDEs for Python. One example is Visual Studio CODE:

https://code.visualstudio.com/

VS Code can also be run online without installation:

https://vscode.dev/

“Hello World” in Python


A great way to get started with any programming language is to do your first “hello world” algoritm.

1. In your IDE, create a new file named hello.py


2. In the editor, enter the following code on line 1:

print("Hello World")

3. In VS Code, you can run the Python code directly in the built-in terminal by pressing the play button.

4. The words “Hello World” should now be printed in the terminal.

The Three Basic Concepts of Programming in Python

1. Sequence

For example, if you want to make a program that extends the previous “hello world” application but instead greets the user with his or her name, you need an algorithm with a function that is called and a sequence of at least two statements.

  1. Have the user enter their name and store the name for later use.
  2. Print the text so the user can read it.

Example of a Sequence With Input and Output in Python:

name = input("Enter name: ")
print("Hello", name + "!")

2. Selection

Selection is a type of statement that allows you to check if a condition is met before taking another action:

If this -> do this

Example of Selection in Python:

In this example we will check if the name entered by the user is Santa.

name = input("Enter name: ")
 
if name == "Santa":
    print("Hi Santa, I promise I have been good this year!")
else:
    print("Hello", name + "!")

Exercise

  • Write a program that asks for a password.
  • Store the password in a variable and when you click the button compare the password with the input.
  • Congratulate the user if the password is correct.
  • Let the user know if the password is incorrect.

3. Iteration (loop)

Iteration is a sequence of instructions that are executed over and over again.

Here we will use the Python for statement to make a loop that will print the name a user-defined number of times.

name = input("Enter name: ")
numberoftimes = int(input("How many times: "))
 
for x in range(numberoftimes):
    print("I ❤️ " + name + "!")

NOTE: Note that in Python we have to convert (typecast) the input string to Integer so we can use the numbers in our loop using the int() function.

Exercise

  • Write a program in Python to display the multiplication table for a given number.
  • The multiplication table should stop at 10

Tip:

  1. Use the variable used in the for statement (often x or i) to do the calculation
  2. It can help in this case if you set range so it starts at 1 and ends at 11. (The reason is that the for statement starts counting at 0 and we don’t want to include that calculation): for x in range(1,11)
  3. Use the str function to convert our integer variables into strings so that we can print them, e.g.: str(x)

Tutorials and Courses

There are a lot of good tutorials for getting started with Python, for example this one from freeCodeCamp:

Use Your New Python Skills

The Python Coding Challenge:

Create your own simple program that takes data from the user and sends back a response that changes depending on the data entered.