First Steps

Python Syntax Basics

Learn some Python syntax basics


We have already learnt that you can name a variable as you wish.

These are all valid variable names:

num a_b _num num_ NUM num123 nUm
Python

However, there are certain restrictions.

A variable name cannot start with a number. Let's see what happens if we try:

1_num = 1 print(1_num)
Python
Output

Python will also not accept any special characters like .-+:,;()/#*'"? in your variable names. They are reserved for other functionalities.

Also, be aware that variable names are case sentive.

The following are 2 different variables.

num=10 NUM=5 print(num) print(NUM)
Python
Output

What will be the output?

num_ONE = 1 print(num_ONE)
Python

What will be the output?

num?one = 1 print(num?one)
Python

Another important aspect of the Python syntax is indentation.

Indentation refers to the whitespace at the beginning of a code line.

num=10 num_with_indentation=10
Python

Your Python program will throw an error if it encounters unexpected whitespace at the beginning of a code line. Let's see what happens if we use unnecessary indentation:

num_with_indentation=10 print(num_with_indentation)
Python
Output

What will be the output?

num = 0 print(num)
Python