Title: Theory / Important / CS / Programming / Python / Manual{ / Other
Tags: FromInstruction computer_to_instruction hasNotNewEffectReturnsMeaning some_instruction fromMath automatedNewLineAfterCommaSpace mathToDef récupéré
On every note of this deck, unless a note says otherwise:
Language: Python

Instruction: (object1)
Effect: object1
Chapter: 3
Section: 2

Instruction: object.__init__(
  self[,
  ...]
)
Effect: Called after the instance has been created (by __new__()), but before it is returned to the caller. The arguments are those passed to the class constructor expression.
Chapter: 3
Section: 3.1
Returns: None

Question: To create proper new:
Answer: call super().__new__(cls[,...])
Chapter: 3
Section: 3.1

Instruction: x_1 != x_2, and other comparison
Effect: If the type of one of the x_i is subclass of x_3-i, the comparison function of x_i is used. Otherwise the comparison of the left operand is used
Chapter: 3
Section: 3.1

Instruction: object.__hash__(self)
Chapter: 3
Section: 3.1
Returns: An integer such that two equal objects return the same integer

Question: Restriction for hash:
Answer: Defined only on unmutable objects
Chapter: 3
Section: 3.1
Answer2: Defined only on objects which admits an __eq__() method
Answer3: __hash__ = None for class whose hash should not exists
Answer4: if x.__eq__(y) then x.__hash__() == y.__hash__()

Name: Default eq function
Definition: A function which returns false, apart when the object is compared to itself.
Chapter: 3
Section: 3.1

Name: Default hash function
Definition: A function f such that x==y implies f(x)==f(y). If __eq__ is overided, it is set to None.
Chapter: 3
Section: 3.1
Context: Python

Instruction: _
Effect: Ignored. It serves to help readability
Context: Middle of a number literal
Chapter: 2
Section: 4.5

Instruction: z.real
Effect: The real part of a complex
Chapter: 3
Section: 2

Instruction: z.imag
Effect: The imaginary part of a complex \(z\)
Chapter: 3
Section: 2

Instruction: s.leng()
Effect: The length of the sequence \(s\)
Chapter: 3
Section: 2

Instruction: s.ord()
Effect: converts a code point from its string form to its int form
Chapter: 3
Section: 2
Typ: integer in the range 0 - 10FFFF

Instruction: s.chr()
Effect: converts a code point from its int form to its string form
Chapter: 3
Section: 2
Typ: length 1 string object

Instruction: str.encode()
Effect: convert a str to bytes using the given text encoding
Chapter: 3
Section: 2
Typ: bytes

Instruction: str.decode()
Effect: convert a bytes to str using the given text encoding
Chapter: 3
Section: 2
Typ: string

Instruction: ()
Effect: The empty tuple
Chapter: 3
Section: 2

Instruction: object_1, ... ,object_n
Chapter: 3
Section: 2
Returns: A tuple with n objects, whose ith object is object_i

Instruction: object,
Chapter: 3
Section: 2
Returns: A tuple with 1 object
Extra: the extra comma indicate to create a tuple

Instruction: o.__doc__
Effect: o's documentation, or None if unavailable
Chapter: 3
Section: 1
Variables: o a function/module/class

Instruction: o.__name__
Chapter: 3
Section: 1
Returns: The name of o
Typ: Writable
Kind: o a function/module/class

Instruction: f.__qualname__
Effect: The function’s qualified name
Chapter: 3
Section: 1
Typ: Writable

Instruction: o.__module__
Chapter: 3
Section: 1
Returns: The name of the module in which o was defined.
Variables: o a function/class
Typ: Writable

Instruction: f.__defaults__
Effect: A tuple containing default argument values for those arguments that have defaults, or None if no arguments have a default value
Chapter: 3
Section: 1
Typ: Writable

Instruction: f.__code__
Effect: The code object representing the compiled function body.
Chapter: 3
Section: 1
Typ: Writable

Instruction: f.__globals__
Effect: A reference to the dictionary that holds the function’s global variables — the global namespace of the module in which the function was defined.
Chapter: 3
Section: 1
Typ: Read only

Instruction: f.__dict__
Effect: The namespace supporting arbitrary function attributes.
Chapter: 3
Section: 1
Typ: Writable

Instruction: f.__closure__
Effect: None or a tuple of cells that contain bindings for the function’s free variables.
Chapter: 3
Section: 1
Typ: Read-only

Instruction: f.__kwdefaults__
Effect: A dict containing defaults for keyword-only parameters.
Chapter: 3
Section: 1
Typ: Writable

Instruction: f.__self__
Effect: The class instance object
Chapter: 3
Section: 2

Instruction: x[i]
Effect: Abbrevation for type(x).__getitem__(x,i)
Chapter: 3

Instruction: Setting a special method to None
Effect: indicates that the corresponding operation is not available.
Chapter: 3

Instruction: foo.__format__(
  self,
  format_spec
)
Chapter: 3
Section: 3.1
Returns: a “formatted” string representation of an object.
Variables: format_spec argument is a string that contains a description of the formatting options desired
foo: a python object
Abbreviation: {foo!format_spec} in f-string