Skip to content

Instantly share code, notes, and snippets.

View NMZivkovic's full-sized avatar

Nikola Živković NMZivkovic

View GitHub Profile
from pymongo import MongoClient
rc = "Rubik's Code"
f"{rc=}"
rc = "Rubik's Code"
f"{rc} is awesome!"
from typing import final
@final
class Song:
artist: str
title: str
album: str
year: int
class Derived(Song): # ERROR: Can't inherit from final class "Song"
from typing import Literal
def nBackAtYa(n: Literal[11, 33, 66]):
if n < 111:
return n
else:
raise ValueError('n must less than 111')
def nBackAtYa(n: int):
if n < 111:
return n
else:
raise ValueError('n must less than 111')
from typing import TypedDict
class Song(TypedDict):
artist: str
title: str
album: str
year: int
song: Song = {'artist': 'Nikola Nezit', 'title': 'Three Suns Halo', 'album': 'Triad', 'year': 2013}
from typing import TypedDict
class Song(TypedDict):
artist: str
title: str
album: str
year: int
song: Song = {'artist': 'Nikola Nezit', 'title': 'Three Suns Halo', 'album': 'Triad', 'year': 2013}
def function(a, b /):
print(a + b)
# Invalid
function(a = 5, b = 6)
# Valid
function(5, 6)
def function(a, b /, c, *, d):
print(a + b + c + d)