Notes on Python Syntax


I’ve been learning python for some time and would like note the nice language aspects of Python programming syntax.

1. Multiple statements on a single line.

In python, normally, to keep a piece of code clean, it is recommended to only put one statement at one line. However, in python, it supports the mutiple statements on a single line, similar to C/C++, Java etc. The delimiter to separate the statements is ‘;’ (semicolon)

For example,

x = 1; y = 1; z = 1

2. while else statement.

using while-else is handly and convenient. For example, instead of writing:

if A:
    while A:
        pass
else:
    pass

A much simpler syntax would be:

while A:
    pass
else:
    pass

3. while on a single line. Sometimes it is shorter to write a single-while statement, for example,

while i < 100: i += 1; print i

4. pass statement is a null statement. It is used to occupy a place that is not implemented yet. For example,

def work():
    pass

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
220 words
Last Post: Codeforces: A. The number of positions
Next Post: Using Tkinter in Python GUI programming

The Permanent URL is: Notes on Python Syntax

Leave a Reply