Language Syntax

Python programming language has simple easy-to-use syntax, making it the perfect language for someone trying to learn computer programming for the first time. Python syntax rules are as follows–

1. No command terminator: In Python, there is no command terminator, which means no semicolon ; unlike C, C++ or Java programming languages.

print("Hello World!")

2. Code Indentation: It provides no curly brackets { } to indicate blocks of code for class and function definitions or flow control (e.g, if..else, while, for etc.). Blocks of code are indicated by line indentation, which is strictly followed.

if a > b:
print("a is greater than b")
else:
print("a is lesser than b")

3. Python Quotation: In Python programming, we can use single quotes '', double quotes "" and even triple quotes ''' """ to represent string literals (i.e. string constants).

word = 'word'
sentence = "This is a sentence."
paragraph = """This is a paragraph.
It contains multiple lines and sentences."""

4. Python Comments: In python, we can write comments in our program using the symbol  #  at the start to make the code more readable. They can be placed anywhere in the program. A comment is ignored while the python code is executed.

# This is a comment.

We can also have multi-line comments using triple-quoted strings:

'''
This is a multi-line
comment.
'''

5. Multi-Line Statements: Python allows the use of the line continuation character ( \ ) to denote multi-line statements.

sum = 100 + \
200 + \
300

6. Multiple Statements in a Single Line: We can write more than one separate executable statements in a single line, we should use a semicolon ; to separate these statements.

print("First line");  print("Second line");  print("Third line");