Dana Vrajitoru
C151 Multi-User Operating Systems

Introduction to Python

Python Introduction

Features of Python

Syntax Rules

Control Structures

Built-in Data Structures

Functions and Parameters

More Built-in Functions

Example of Conditional

def check_type(x):
    if type(x) == type(0):
        print x, "is an integer"
    elif type(x) == type(1.0):
        print x, "is a float"
    elif type(x) == type(""):
        print x, "is a string"
    elif type(x) == type([]):
        print x, "is an array"
    ...

Example of while/else

def Euler(a, b):
    if b==0:
        return a
    r = a % b
    while r:
        a = b
        b = r
        r = a % b
    else:
        print "a divisible by b"
        return b
    return r

Booleans

Default Values for Parameters