1 / 13

REPL

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

alayna
Download Presentation

REPL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. REPL Read-Eval-Print-Loop (or Interactive Environment)

  2. Recap What have we learned so far?

  3. Program = Data + Operations + Assignment + Control Flow

  4. Data • Primitive Type • int • float • string • boolean • Compound Type • list

  5. Operations • Arithmetic • +, -, *, //, % etc. • Boolean • and, or, not • <, <=, >, >=, ==, != • String • +, *, [], [:], str(), len etc. • List • +, [], split, join

  6. Expressions • Combinations of data and their operations • Arithmetic • Boolean • Have precedence and associativity rules to determine order of evaluation • When in doubt, use parentheses ()

  7. 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

  8. 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)]

  9. Controlling Program Flow: While while <boolean expression >: [while code block] [outside while code block]

  10. 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

  11. 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)

More Related