Get Started with Python in under 10 minutes
Tags: python, coding, tutorial, programming
Published: 2019-08-11 06:30:28

So you want to learn how to code? You have no prior coding experience or are you coming from another programming language? You have come to the right place. This is an ultimate beginners guide to Programming with Python. We’re not going to go knees deep into programming. But we’re going to get started and write code as quickly as possible. So let’s get started!

## Part I: Setting up the coding environment

You can write Python code on your terminal, VSCode or even on a dedicated IDE like PyCharm. But since you’re a beginner we don’t want to you waste time setting one up. You can do it later. For now, you can look to the cloud for an easy and instant IDE setup.

Go to [Repl.it](https://repl.it). It gives you an instant IDE to learn, build, collaborate, and host all in one place.

1. Create a new Repl.

1. Choose Python (not Python 2.7).

1. Name your Repl.

1. Create Repl.

![Follow the GIF if you have any confusions.](https://cdn-images-1.medium.com/max/2000/1*QXQFArTYxQlZfFzI9YyysQ.gif)*Follow the GIF if you have any confusions.*

Now that we have an IDE, let’s write our first line of code!

## Part II: Let’s Write Some Code!

Before you start coding, in any programming language it’s a tradition to get started by writing code to print “Hello World!” So let’s not break tradition and do just that!

## 1. Let’s print stuff using Python :

The middle section of the repl is where you write your code. The right side is called a console. Think of it as the middle man between you and python. The console is where you’ll do your input/output to your python program.

![](https://cdn-images-1.medium.com/max/6816/1*CNoFX5BkVE5aLSN_vPMnKg.png)

To print something on the console, we use the print() statement. Specify the text you want to print inside ‘ ’ or “ ” quotes.

    print('Hello World!')
    print("Hello World!")

After writing the above code in the console hit the Run button on top.

![](https://cdn-images-1.medium.com/max/2000/1*mH4OsX34RB1-mmU18PbEBQ.gif)

Congratulations! You have written your first piece of Python Code! Now let’s go ahead write some code that actually does something.

By now you should be familiar with how to use repl.it. From now I’ll embed the repl directly here in the article so you don’t have to keep switching tabs which can quickly become really annoying. So you can write in your own code and run them right here!

## 2. Comments in Python

Comments are used to explain what your line of code does. You can write a comment using the ‘#’ symbol. The ‘#’ tells python to ignore the line and not to execute it. You can even add # symbol before existing lines of code to make it a comment. You can also have multi-line comments by starting and ending it with ‘’’. Refer the example below for clarity.

Tap the big green play button below to execute the code. You can also edit the code here. Add in your lines of code and run them!

{% replit @Gothamv/comments %}

## 3. Variables in Python

Think of variables like a box, where you store stuff. You can store numbers, characters, sentences and so much more. For now let’s work with numbers, characters, and sentences(strings).

### Let’s assign a number to a variable.

Equal to symbol ‘=’ is an assignment operator and is used to assign values to variables.

    myVariable = 13
    myVariable2 = 12.6969

You can go ahead and check the type of your variable using the type() statement, and passing in your variable name inside of the type().

    type(myVariable)
    type(myVariable2)

    # To view this in the console pass the above statement inside the print function like this :

    print(type(myVariable))
    print(type(myVariable2))

When you run the above code you’ll see that myVariable returned <class ‘int’> and myVariable2 returned <class ‘float’>.

You might’ve guessed it. It’s because 13 is an integer and 12.6969 is a decimal number which we call it as floating-point numbers in the programming world.

### Let’s assign a character/string to a variable.

To assign a character to a variable, you must enclose the value of the variable in ‘ ’(single quotes) or “ “(double quotes).

Characters by convention have a length of one and use ‘ ‘ (single quotes).
Strings are sentences or have more than one character generally enclosed in 
“ “ (double quotes).

    char1 = 'a'
    string1 = "Musk Cult"

Run the code below and see for yourself!

{% replit @Gothamv/variablesInPython %}

## 4. Arithmetic Operations in Python

Remember we created number valued variables above? You can perform mathematical operations on them. Let’s see the implementation of some of the basic arithmetic operations in math.

The code below is pretty self-explanatory. Run the code and check it out.

    myVariable1 = 6
    myVariable2 = 3

### Addition + :

    myVariable + myVariable2

    # To see the result on the console :
    print(myVariable + myVariable2)

### Subtraction - :

    print(myVariable - myVariable2)

### Multiplication * :

    print(myVariable * myVariable2)

### Division / :

    print(myVariable / myVariable2)

{% replit @Gothamv/arithmetic %}

## 5. Printing variables

Previously we printed the result of the arithmetic operations directly using the print statement. But there’s a better way to do this; store the result in another variable.

    result = myVariable + myVariable2
    print(result)

You can also print the values of variables along with a print statement. Let me show you what I’m talking about. Run the code below.

    print("The result of addition is :",result)

{% replit @Gothamv/printingVariables %}

So instead of having just a number being printed in the console, we can have meaningful statements.

You can also specify a particular place in the print statement where you want your variable to be printed.

    print("%s is the value of myVar!" % myVar)

Instead of the comma, we used after the string inside the print statement we use the ‘%’ here. ‘ %s’ is called a string literal which is used to specify the position inside a string where you want the value of a variable to be.

    print("The result of addition of %s and %s is : %s" % (myVar,myVar2,result))

Here we wanted to place multiple variables so, after the % add a parenthesis ( ) and mention the variables in the order you want them inside the print statement separated by a comma. Run the code below and see for yourself.

{% replit @Gothamv/sPrinting %}

## 6. Getting input from the user.

Previously we assigned values to variables ourselves. Instead, we can get the value of the variable from the user. Here’s how :

We use the input() statement. Equate the variable to an input statement. And inside the parathesis pass in your statement inside single quotes or double-quotes.

    myVar = input("Enter the First Number : ")
    myVar2 = input("Enter the Second Number : ")

If you check the type of myVar and myVar2 it’s going to be <class ‘str’>.
It’s because by default the type of the input function is a string. But we can perform mathematical calculations only on numbers. So to convert this to a number we do something called a ‘Type Casting’. We wrap the input statement inside an int(). This converts the string type to integer typer. If you want to work with decimals use float().

    myVar = int(input("Enter the First Number : "))
    myVar2 = int(input("Enter the Second Number : "))

{% replit @Gothamv/inputFromUser %}

And there you have it! You’ve written your first piece of code that does something! We’ll learn more about programming and python in upcoming posts!

### And that’s pretty much it for the basics.