This is an old revision of the document!


Python Crash Course

Command Line (CLI)

Start REPL (Read Execute Print Repeat) interactive mode and exit:

shell$ python
>>> 
>>> quit()
shell$

Execute files:

shell$ python filename.py
shell$ python filename.py arg1 arg2 arg3

Basics

Variables:

a = 10
b = "Ana are mere"
c = [1, 2, 3]

Functions:

def my_function(a

Input/Output

Data Structures

Lists:

l1 = [1, 2, 3]
l2 = [10, 'mere', [25, 20], {}, ]

Object Oriented Programming



Conditions & Loops

i = 0
cnt1 = 0
while i < 10:
    if i%2 == 0:
        cnt += 1
 
 range(), len(), type()

Built-in Functions

range(start, stop, step)
for i in range(5):
    print(i) # 0 1 2 3 4
 
for i in range(3, 10, 2):
    print(i) # 3 5 7 9

In Python 2.x range generates first the entire list of numbers and then iterates through it:

for i in range(5)

References

ic/resurse/python.1601117400.txt.gz · Last modified: 2020/09/26 13:50 by acosmin.maria
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0