Python 101: Getting Started with Python

·

4 min read

A Short Introduction

Hello future programmers. I have just started a series about learning Python from start to finish. We will be covering a wide variety of topics from your first steps with Python, to data analysis and machine learning.

I am Atom and am fluent in many languages, including Python. Important to know that if you have any questions with any of these topics, don't hesitate to leave a comment below and I will answer them as soon as possible!

What is Python?

Python is a very popular programming language created by Guido Van Rossum released in 1991.

Python is used for:

  • Web development (server-side)
  • Software development
  • Mathematics
  • System scripting
  • Automation
  • Machine learning
  • Data analysis
  • and much, much more.

What can Python do?

  • Python can be used on a server to create web applications.
  • Python can be used alongside software to create workflows.
  • Python can connect to database systems. It can also read and modify files in your local file system.
  • Python can be used to handle big data and perform complex mathematical tasks.
  • Python can be used for rapid prototyping, or for production-ready software development.

Why use Python?

  • Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.).
  • Python has a simple syntax to the average English language.
  • Python has a syntax that allows developers to write programs with fewer lines than some other languages.
  • Python runs on an interpreter system, meaning that code can be executed as soon as it's written. This means that prototyping can be very quick.
  • Python can be treated in a procedural way, an object-oriented way or a functional way.

How do I Install Python?

Many PCs and Macs will automatically have python preinstalled.

To check if you have Python, run the following command on the Command Line:

python --version

If you are returned an error, it means that you do not have Python installed on your computer. You can download it for free on the Python official website.

Python Quickstart

Python is an interpreted language, this means that you as a developer have to write Python (.py) files in a text editor and then input those files inside the interpreter to be executed.

To run a Python file, you must run the following command:

python <file>.py

Note: Replace file with the name of your file.

For this example, we will name our file test.py. Let's write our first lines of code!

print("Hello, world!")

After running the file, you should get the following result inside your terminal:

Hello, World!

Python CLI

To test a short amount of code in Python, sometimes it's the quickest and easiest to not write the code inside a file. This is made possible because Python can be run as a command itself.

Run the following command:

python

This should enter you inside a screen displaying your Python version and other information such as possible commands (help, copyright, credits, or license).

You can write your code here after the >>>.

>>> print("Hello world")

It should respond with:

Hello world

When you are done in the Python command line, you can simply type the following command to quit the CLI (Command Line Interface).

>>> exit()

Correct Syntax

Syntax determines how you should write your code.

In computer science, the syntax of a computer language is the set of rules that defines the combinations of symbols that are considered to be correctly structured statements or expressions in that language. - Wikipedia

So, this definition contains a lot of words, which may be overwhelming. Let me narrow this down for you. Programming syntax is just the set of rules you have to follow in order to write proper code. For example, when you are writing essays, you have to make sure each paragraph is indented. Or, you have to have a period at the end of every sentence. Those examples exactly represent the idea of programming syntax.

Let's learn more about proper syntax!

Python Code Indentation

Indentation refers to the spaces at the beginning of a code line. Where in other programming languages the indentation is for readability only, the indentation in Python is very important.

Python uses indentation to indicate a block of code.

For example, this code snippet contains valid syntax:

if 3 > 2:
  print("Three is greater than two!")

But, this code snippet contains invalid syntax:

if 3 > 2:
print("Three is greater than two!")

These two may contain the same lines of code, it's just that they don't have proper indentation. If you are unfamiliar with if and else statements, don't worry about it. You will learn about it in a future tutorial.

Conclusion

In this tutorial, you have learned:

  • What is Python?
  • Why should you use Python?
  • How to install Python?
  • How to use Python CLI
  • Introduction to syntax

There is more towards Python syntax, and it will be covered in the next tutorial. If you have any suggestions on something to add, post it in the comments, and I'll be sure to accommodate your suggestions.

Stay safe and have a wonderful week!