backlinks to this page:
Plugin Backlinks: Nothing was found.
Github:
Important python concepts
callable: a function or some object than can be called (function call)
argument: parameter is what is declared in the function, while an argument is what is passed through when calling the function
parameter: parameter is what is declared in the function, while an argument is what is passed through when calling the function
comprehension: basically an in-line for…loop that creates an data container.
>>>a = [x**2 for x in range(5) ] >>>a [0, 1, 4, 9, 16] >>> type(a) <class 'list'>
>>>a = [x**2 for x in range(20) if x%2==0] >>>a [0, 4, 16, 36, 64, 100, 144, 196, 256, 324]
>>>a={x**2 for x in range(5)} >>>a {0,1,4,9,16} >>>type(a) <class 'set'>
>>>a = {x:x**2 for x in range(5)} >>>a {0: 0, 1: 1, 2: 4, 3: 9, 4: 16} >>>type(a) <class 'dict'>
>>>g = (x**2 for x in range(5)) >>>type(g) <class 'generator'> >>>for element in g: print(element) 0 1 4 9 16 >>>
tuple
on a list comprehension or generator:
>>> # tuple from list comprehension >>> a = tuple([x**2 for x in range(5)]) >>> a (0, 1, 4, 9, 16) >>> type(a) <class 'tuple'> >>> # tuple from generator >>> b = tuple((x**2 for x in range(5))) >>> b (0, 1, 4, 9, 16) >>> type(b) <class 'tuple'>
for
loop. See also __iter__
__hash__
), and it can be compared to other objects (see __eq__
). Hashable objects that compare as equal must have the same hash value.” (from https://realpython.com/python-data-structures/)
a function that 'decorates' another function. Can in python coded using the @
character.
examples:
to decorate a method as a classmethod or staticmethod, write the decorator line above the method.
class Person: @classmethod def show_all_persons(cls): print("...") def __init__(self): print("...")
return
statement but instead has an yield
statement. Yield returns a value to the function calling code, but the function “stays alive sleeping” → it remembers all it local variables and scope. The next time the function is called, it continues after the yield statement. Generators are good for processing large data, like files