Python: A fairly simple, readable, interpreted, general-purpose and high-level programming language.
We are starting a tutorial on Python 3 programming language, you can call it web-based-Bootcamp. In this series, 'Learn Python 3' the aim is to teach you Python 3 as quickly as possible so you can start building programs. 'Learn Python 3' course(Tutorial) is for people of any age, doesn't matter if you haven't programmed before in Python or new to programming. We shall start from very basics of programming and by time we will be learning advance stuff and deep dive into Python.
Currently, Python has two versions available 2 and 3. Many companies are still using Python 2 and many useful software written in Python 2 that's why it's being used widely, on the other hand, people are adopting Python 3 and porting their Python 2 software to Python 3. In this tutorial series, we will use latest version of Python 3 and it's very easy to learn Python 2 after you acquire knowledge of Python 3. There are some syntax differences in both versions. With time, we'll construct tutorial as per user needs and make it better for all of you.

You'll learn in this tutorial:
  • Traditional 'Hello world' program
  • Variables

First of all you need to setup Python on your system. If you are using Linux or Mac then your OS have it installed already, if you want to get latest version of Python then follow this guide for Linux. For Mac and Windows check official website of Python.

Note: Before you start, make sure you run each given code to understand that how things work!

Your first Python program

If you are a new to programming then today you are going to write very first program. It is traditional and almost every programmer has done it regardless of programming language.
In Python it is very very simple to do "Hello World!" program. You just need to write one line. There are numerous ways to run Python program, we keep it simple for now. In Linux, just type the version of Python installed on your system for example: python3.5.
If you don't want to install Python or don't know how to install it then you can use online Python console called "".

We are going to do it other way by creating a file and write our code in it. Then we go to Terminal and run file with Python3. You can see this way in the following screenshot.
Once you are ready with Python console then type the following code in it and hit enter to run it.
print("Hello World!")
You will see the output like this:

Congratulations, on writing your first program in Python. Lets see what we are doing here:
print( ) => it prints message to the screen, or other output device. The message can be anything string or object.
"Hello World!" => It is a message between double quotes, it is called string. We can surround string with double " " quotes or single ' ' quotes, both quotation marks functions same for example 'Hello World!'.

Variables in Python

In programming variables used to store data or we can call them containers where we put something in them in-order to access stored data later. Every variable hold certain value(s) and variables are mutable that means we can change variable's value at any time in our program.
Variables can store all sort of data like: numbers, strings, booleans and objects.

There are some rules when defining a variable in Python programming language:
  • Variable names should be descriptive, for example: my_message. Avoid using very short variables such as my_m, you will scratch your head later understanding your program.
  • Be careful using lowercase letter 'l' and uppercase letter 'O' because they can be mixed with 1 and 0.
  • Don't use Python reserved keywords and function names.
  • Variables can only contain letters, numbers and underscores.
  • Variable can't start with numbers.
  • Spaces are not permitted in variables.

Lets see how to create variables:

We will modify our first 'Hello World' program to show you, how variables work!

message = "Hello World!"

First line of the program, the string 'Hello World!' is stored in variable called 'message'. We can have give any name to the variable.
Then we are using print function to output our message on the screen. Also, we can defined variable 'message' as many times as we want in our program.
We can reassign a new value to 'message' in the same program and there won't be any issue. Lets see an example:
message = "Hello World!"

message = 'We are defining another variable'

Another example with numbers:
number = 100

Assign variable to another variable
You can also assign a variable which has a value to new variable. See following example for more clarification:
number = 100

new_number_variable = number
In this example, we assigned value of variable 'number' to new variable called 'new_number_variable'. Now we can use 'new_number_variable' to print the same value.

Compact assignments
Python allows us to make multiple assignment in just one line, it is useful when you want to make your program compact but make less readable/complex:
varX, varY, varZ = 'Hello', 50, '1 Penny'

Multiple assignments
We can assign same value to multiple variables. In the following example, all variables hold the same value, you can print each variable to check its value:
my_number = number = last_number = first_number = 200

That's it for today.
Stay tuned for more tutorials on Python 3 programming language! Happy coding.
Share To: