L&L S4S1
2.7 - 03/07/2010
3.7 - 27/06/2018
3.8 - 14/10/2019
3.9 - 05/10/2020
3.10 - 04/10/2021
name1 = "Shiniya" name2 = "Dahmane" name3 = "Qiang" print(f"name1={name1}") print(f"{name2=}") print(f"{name3=}")
name1 = "Shiniya" name2 = "Dahmane" name3 = "Qiang" print(name1) print(name2) print('name3=',name3)
Shiniya
Dahmane
name3=Qiang
name1=Shiniya
name2=Dahmane
name3=Qiang
>>> version = "3.8"
>>> version == "3.8"
True
>>> version is "3.8"
<>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
<ipython-input-29-fb0be97c5f9d>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
version is "3.8"
Out[29]: False
>>> version = "3.5"
>>> version == "3.5"
True
>>> version is "3.5"
False
test = [ ('a','b'),('c','d') ]
TypeError: 'tuple' object is not callable
test = [ ('a','b'),('c','d') ]
SyntaxWarning: 'tuple' object is not callable; perhaps you missed a comma?
import collections
from timeit import timeit
P = collections.namedtuple(
"P",
"name team"
)
qiang = P("Qiang","LSE")
timeit( "qiang.team", globals=globals(), )
0.07939400000032037
0.05426930000066932
161528168
181719232
import sys
sys.getsizeof(
list(
range(20191014)
)
)
a_dict = { x: '1', y: '2', z: '3' }
b_dict = { i: '4', j: '5' }
c_dict = a_dict | b_dict
print(c_dict)
a_dict = { x: '1', y: '2', z: '3' }
b_dict = { i: '4', j: '5' }
c_dict = {**a_dict, **b_dict}
print(c_dict)
a_dict = { 'x': '1', 'y': '2', 'z': '3' }
b_dict = { 'i': '4', 'j': '5' }
a_dict |= b_dict
print(a_dict)
a_str = "Elena thought Filipa hated dogs".removeprefix("Elena thought ") print(a_str) b_str = "Dario likes cats ?".removesuffix("?") print(b_str)
from typing import (
List,
Dict,
)
def this_is_a_func( var_a: List ) -> Dict:
return final_dict
my_list = ["Hi", "Levis"
print(my_list)
from typing import Union def old_typing(para: Union[int, float]) -> Union[int, float]: return para*2 print(old_typing(0.3))
def new_typing(para: int | float) -> int | float: return para*2 print(new_typing(0.3))
names = ["Filipa", "Victor", "TAHAR", "GUILLAUME", "Howard"] roles = ["DS", "DEVOPS", "MLE", "DE"] list(zip(names, roles))
names = ["Filipa", "Victor", "TAHAR", "GUILLAUME", "Howard"] roles = ["DS", "DEVOPS", "MLE", "DE"] list(zip(names, roles, strict=True))
match subject:
case con1:
do case con2: do case con3: do case _: do
if
do
elif
do elif
do ... else
do
def test(n): match n: case 0 | 1: return 1 case _: return n*3 test(5)
def test(n): if n == 0 or n == 1: return 1 else: return n*3 test(5)
roles = ("DS", "MLE", "DEVOPS") #roles = ("DS", "MLE", "DEVOPS", "DE") match roles: case filipa, saeed, victor: print(f"{filipa=},{saeed=},{victor=},") case filipa, saeed, victor, vicente: print(f"{filipa=},{saeed=},{victor=}, and {vicente=}")
def normalise_biz(biz_logic): """Normalise biz logic to (region, (con1, con2, con3, conx)).""" match colour: case (con1, con2, con3): region = "EU" conx = "" case (con1, con2, con3, conx): region = "Global" case (region, (con1, con2, con3)): conx = "Frida" case (region, (con1, con2, con3, conx)): pass case _: raise ValueError("Unknown biz logic.") return (region, (con1, con2, con3, conx)) print(normalise_biz(("Caravaggio", "Dali", "Da Vinchy"))) print(normalise_biz(("Caravaggio", "Dali", "Zheng", "Frida"))) print(normalise_biz(("Mexico", ("Caravaggio", "Dali", "Zheng")))) print(normalise_biz(("Global", ("Caravaggio", "Dali", "Zheng", "Frida"))))