Python Language: Difference between revisions
Line 2: | Line 2: | ||
* [[Python#Subjects|Python]] | * [[Python#Subjects|Python]] | ||
=Reserved Words= | =Reserved Words= | ||
Reserved words can only be used to mean the thing Python expects them to mean. They cannot be used as [[#Variables|variable names]] or [[#Identifiers|identifiers]]. | Reserved words can only be used to mean the thing Python expects them to mean. They cannot be used as [[#Variables|variable names]], [[#Functions|function names]], [[#Classes|class names]], or [[#Identifiers|identifiers]]. | ||
{| | {| | ||
| <code>False</code> || <code>class</code> || <code>return</code> || <code>is</code> || <code>finally</code> | | <code>False</code> || <code>class</code> || <code>return</code> || <code>is</code> || <code>finally</code> | ||
Line 18: | Line 18: | ||
| <code>break</code> || <code>except</code> || <code>in</code> || <code>raise</code> | | <code>break</code> || <code>except</code> || <code>in</code> || <code>raise</code> | ||
|} | |} | ||
=Constants= | =Constants= | ||
Constants are fixed values, they do not change throughout the program. Constants can be numeric, or strings, which can be single quoted or double quoted. | Constants are fixed values, they do not change throughout the program. Constants can be numeric, or strings, which can be single quoted or double quoted. |
Revision as of 05:19, 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, function names, class 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
|
Constants
Constants are fixed values, they do not change throughout the program. Constants can be numeric, or strings, which can be single quoted or double quoted.
Variables
Statements
In Python 2, print
used to be a statement, while in Python 3, print()
is a function.
Assignment Statement
x = 1
The assignment accepts expressions:
x = x + 1
Functions
Expressions
Operators
+, = are operators.
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.