Python: Difference between revisions
Jump to navigation
Jump to search
Line 43: | Line 43: | ||
a = 1 | a = 1 | ||
b = 'something' | b = 'something' | ||
print(a | print(a) | ||
print(b) | |||
</syntaxhighlight> | |||
Functions: | |||
<syntaxhighlight lang='py'> | |||
def function_name(arguments): | |||
<function body> | |||
def something(a, b): | |||
c = a + b | |||
return c | |||
</syntaxhighlight> | |||
Conditions: | |||
<syntaxhighlight lang='py'> | |||
if a == 1: | |||
print('something') | |||
else | |||
print('something else') | |||
</syntaxhighlight> | |||
Loops: | |||
<syntaxhighlight lang='py'> | |||
while <condition>: | |||
code-block | |||
while x < 5: | |||
x = x + 1 | |||
print | |||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 02:10, 13 May 2021
Internal
Subjects
Installation
Mac
brew install python3
Linux
yum install python3
Organizatorium
- https://opensource.com/article/18/1/running-python-application-kubernetes
- Each installation of Python may have different modules installed. Python determines the path to its modules by examining the location of the
python3
executable. - Python environments on Mac:
- ~/Library/ApplicationSupport/iTerm2/iterm2env/versions/*/bin/python3
- ~/Library/ApplicationSupport/iTerm2/Scripts/YourScript/iterm2env/versions/*/bin/python3
Basic Language
Printing done with print() function.
print('something')
Comments:
# This is a comment
Variables.
a = 1
b = 'something'
print(a)
print(b)
Functions:
def function_name(arguments):
<function body>
def something(a, b):
c = a + b
return c
Conditions:
if a == 1:
print('something')
else
print('something else')
Loops:
while <condition>:
code-block
while x < 5:
x = x + 1
print