Python Language: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 40: Line 40:
=Flow Control=
=Flow Control=
==Sequential Steps==
==Sequential Steps==
Sequential steps have the same indentation level.
==Conditional Steps==
==Conditional Steps==
<syntaxhighlight lang='python'>
<syntaxhighlight lang='python'>

Revision as of 04:47, 22 May 2021

Internal

Reserved Words

Reserved words can only be used to mean the thing Python expects them to mean. They cannot be used as variable names or identifiers.

False class return is finally
None if for lambda continue
True def from while nonlocal
and del global not with
as elif try or yield
assert else import pass
break except in raise

Statements

Assignment Statement

x = 1

The assignment accepts expressions:

x = x + 1

Functions

Expressions

Operators

+, = are operators.

Variables

Identifiers

Python Script

A Python program file is called a Python script - a stored set of instructions that can be handed over to the Python interpreter. Python scripts have the .py extensions.

Flow Control

Sequential Steps

Sequential steps have the same indentation level.

Conditional Steps

if x < 10:
  print('something')

Loops

n = 5
while n > 0:
  print(n)
  n = n - 1

Loops have iteration variables, which are initialized, checked and changed within the loop.

Functions

Organizatorium

  • statement vs function. print is a statement in python 2, print() is a function in python3.