130 likes | 266 Views
REPL. Read- Eval -Print-Loop (or Interactive Environment). Recap. What have we learned so far?. Program = Data + Operations + Assignment + Control Flow . Data. Primitive Type int float string boolean Compound Type list. Operations. Arithmetic +, -, *, //, % etc. Boolean
E N D
REPL Read-Eval-Print-Loop (or Interactive Environment)
Recap What have we learned so far?
Data • Primitive Type • int • float • string • boolean • Compound Type • list
Operations • Arithmetic • +, -, *, //, % etc. • Boolean • and, or, not • <, <=, >, >=, ==, != • String • +, *, [], [:], str(), len etc. • List • +, [], split, join
Expressions • Combinations of data and their operations • Arithmetic • Boolean • Have precedence and associativity rules to determine order of evaluation • When in doubt, use parentheses ()
Assignment and Variables • Variables • Places where data (or values) can be stored • Names at the high-level • Storages (or memory locations) at the low-level • Assignment • The act of placing data (or values) to names (or placeholders) • Variables on LHS = Expressions on RHS
Controlling Program Flow: If-Else if <boolean expression 1>: [code guarded by boolean expression 1] elif<boolean expression 2>: [code guarded by boolean expression 2] else: [code to execute if all fail (False)]
Controlling Program Flow: While while <boolean expression >: [while code block] [outside while code block]
Functions • A way of organizing code • Easy to reason about program flow • Modularity in software • Define a function and make a function call to it • A function definition by itself is an idle code until you activate it with a call to it
Example Function def fact(n): if n == 0: return 1 else: return fact(n-1)*n print fact(12) print fact(0) print fact(5)