This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import weakref | |
import ctypes | |
class Yarrow: | |
def __init__(self, fun_fact): | |
self.fun_fact = fun_fact | |
# creating Yarrow object | |
yobj = Yarrow('insect repellent used in bird nest') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import weakref | |
import ctypes | |
class Yarrow: | |
def __init__(self, fun_fact): | |
self.fun_fact = fun_fact | |
# creating Yarrow object | |
yobj = Yarrow('insect repellent used in bird nest') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass, asdict | |
@dataclass | |
class ThreeD: | |
x: int | |
y: int | |
z: int | |
p = ThreeD(0, 0, 0) | |
print( asdict(p) == {'x': 0, 'y': 0, 'z': 0}) | |
print(asdict(p)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
@dataclass | |
class Animal: | |
no_of_feet: int = 0 | |
no_of_hand: int = 0 | |
@dataclass | |
class Bird(Animal): | |
species: string = '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import fields | |
@dataclass | |
class Cat: | |
name: str | |
breed: str | |
paws: int = 4 | |
dietry: list[str] = field(default_factory=list) | |
whikey = Cat(name='Whikey', breed="Siamese", dietry=['fresh wild caught mackarel', 'smoked cheese']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@dataclass | |
class SummerHoliday: | |
destination: str | |
days: int = 60 | |
sunny: bool = True | |
head_count: int = field(default=10) | |
COASTAL_AREAS: list[str] = field(default_factory=list) | |
def holiday_by_the_sea(self): | |
if self.destination in self.COASTAL_AREAS: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@dataclass | |
class Holiday: | |
pass | |
@dataclass() | |
class Holiday: | |
pass | |
@dataclass(init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False) | |
class Holiday: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass, field | |
@dataclass | |
class SummerHoliday: | |
destination: str | |
days: int = 60 | |
sunny: bool = True | |
def sunny_holiday(self): | |
if self.sunny: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(f'Hello World from {__name__}') | |
def yielding_cube(n): | |
i = 0 | |
while i < n+1: | |
i += 1 | |
yield i*i*i | |
cube_generator = yielding_cube(5) | |
while True: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import package_3 | |
def yield_values(): | |
print("In the yield_values function") | |
from package_3 import call_yield_func | |
call_yield_func() | |
if __name__ == "__main__": | |
yield_values() |