Python Syntax

Python is known for its clean syntax.

The language avoids using unnecessary characters to indicate some specificity.

Semicolons

Python makes no use of semicolons to finish lines. A new line is enough to tell the interpreter that a new command is beginning.

The print() method will display something.

In this example, we have two commands that will display the messages inside the single quotes.

print('First command')
print('Second command')

Output:

First command
Second command

This is wrong due to the semicolons in the end:

print('First command');
print('Second command');

Indentation

Many languages use curly-brackets to define scopes.

Python’s interpreter uses only indentation to define when a scope ends and another one starts.

This means you have to be aware of white spaces at the beginning of each line, they have meaning and might break your code if misplaced.

This definition of a function works:

def my_function():
    print('First command')

This doesn’t work because the indentation of the second line is missing and will throw an error:

def my_function():
print('First command')

Case sensitivity and variables

Python is case sensitive, the variables name and Name are not the same thing and store different values.

name = 'Renan'
Name = 'Moura'

As you could see, variables are easily created by just assigning values to them using the = symbol.

This means name stores ‘Renan’ and Name stores ‘Moura’.

Comments

Finally, to comment something in your code, use the hash mark #.

The commented part does not influence the program flow.

# this function prints something
def my_function():
    print('First command')

To learn more: