Skip to content

Python Multi-line Statements

How python interpret multi-line code into single line code:
  1. python program
  2. physical lines of code(end with a physical newline CHARACTER create by enter)
  3. logical lines of code(end with a logical NEWLINE token)
  4. tokenized
  5. execute
physical newlines vs logical newline

sometimes physical newlines are ignored in order to combine multiple physical lines into a  single logical newline

break implicitly: [], (), {}

break explicitly

multi-line strings

multi-line strings are regular string, not comments (can be used as docstring)

escaped characters(\n, \t), non-visible characters(newlines, tabs) in multi-line are part of string; escaped characters will formatted when print it

ref:

https://github.com/fbaptiste/python-deepdive/blob/master/Part%201/Section%2002%20-%20A%20Quick%20Refresher/01%20-%20Multi-Line%20Statements%20and%20Strings.ipynb

Python Type Hierarchy

Number

  • Integral: Integer, Booleans
  • Non-Integral: Floats, Complex, Decimals, Fractions(1/3)

Collection

  • Sequences
    • Mutable: List
    • Immutable: Tuples, Strings
  • Sets
    • Mutable: Sets
    • Immutable: Frozen Sets
  • Mappings
    • Dictionaries (relate to set)

Callables

  • Built-in Functions
  • User-Defined Fuctions
  • Instance Methods (e.g. len())
  • Built-in Method (e.g. my_list.append(x))
  • Generators
  • Classes
  • Class Instances(__call__())

Singletons

  • None
  • NotImplemented
  • Elipsis operators

Event Queue

When the browser, somewhere outside the JavaScript engine, has the event inside the JavaScript engine that want to be notified of, its get placed in the event queue, and WHETHER OR NOT the event have a function response to it.

The event queue gets looked at by JavaScript when the execution stack is EMPTY.

JavaScript engine is always running synchronously, what happening is that the browser is asynchronously putting things into event queue.

 

let in ES6

let allows the JavaScript engine to use BLOCK SCOPING, means variables are only allowed inside specific block, such as if/else statement which defined by {}

Scope Chain

While running a line of any execution context, if it can’t find a variable, it will look at OUTER ENVIRONMENT to look for that variable, somewhere down below in the execution stack. Which outer environment to look is depend on where this function sit LEXICALLY.

 

 

Function Invocation and Execution Stack

In the execution phase of global execution context, functions already setup in memory, when it execute function invocation command , such as someFunction(), a new execution context created and put to execution stacks (top of the stack). when function invocation finished, will popped of the stack