Basic Structure of Python Code

Q

What is Basic Structure of Python Code?

✍: FYIcenter.com

A

The basic structure of Python code can be described below:

A Python code is a sequence of statements and statement blocks.

Each statement or statement block in a Python code is executed sequentially one by one.

For example, look at the following Python code with line numbers added:

Line 1:  # Python 3: Fibonacci series up to n
Line 2:  def fib(n):
Line 3:      a, b = 0, 1
Line 4:      while a lt; n:
Line 5:          print(a, end=' ')
Line 6:          a, b = b, a+b
Line 7:      print()
Line 8:  fib(1000)

You can identify the following expressions, statements and statement blocks:

  • Line 1 is a comment statement.
  • Line 2 to line 7 is a statement block.
  • Line 3 is an assignment statement.
  • Line 4 to line 6 is a statement block.
  • Line 5 is an expression statement.
  • Line 6 is an assignment statement.
  • Line 7 is an expression statement.
  • Line 8 is an expression statement.

 

Multi-line Statements in Python Code

Statement Syntax and Execution Flow Control

Statement Syntax and Execution Flow Control

⇑⇑ Python Tutorials

2023-06-12, 1239🔥, 0💬