User Tools

Site Tools


python:features

Some Python features

Types

Boolean

True
False

Header, suite/block, clause

if foo == bar:         # header             clause 1
    print('same')          # suite/block    clause 1
else:                  # header             clause 2
    print('different')     # suite/block    clause 2

Selection

if, if/else

if condition:
    suite
if condition:
    suite
else:
    suite

nested if/else

if credits == 90:
    print('Senior')
else
    if credits == 60:
        print('Junior')
    else:
        if credits >= 40:
            print('Sophomore')
        else:
            print('something else')
if credits >= 90:
    print('Senior')
elif credits >= 60:
    print('Junior')
elif credits >= 40:
    print('Sophomore')
else:
    print('something else')

Iteration/repetition

while condition:
    suite:

definite loop: counter controlled repetition, “a program loop in which the number of times the loop will iterate can be determined before the loop is executed.”

indefinite loop: sentinel controlled repetition, “a program loop in which the number of times the loop will iterate is not known before the loop is executed.”

flag/semaphore/sentinel: TODO.

python/features.txt · Last modified: 2017/12/06 01:54 by mithat