PYTHON_MANIFEST

Global Language Specification // v3.x

RETURN_PORTAL
01_DATA_STRUCTURES
# List (Mutable)
items = ["node", 101, 0.5]
items.append("sync")

# Tuple (Immutable)
coords = (10, 20)

# Dictionary (Key-Value)
sys = {"id": 88, "status": "active"}

# Set (Unique items)
unique_ids = {1, 2, 3, 3} # {1, 2, 3}
            
02_COMPREHENSIONS
# List Comprehension
sq = [x**2 for x in range(10) if x > 5]

# Dictionary Comprehension
map = {f"ID_{x}": x for x in range(3)}

# Set Comprehension
chars = {c.upper() for c in "syntax"}
            
03_CONTROL_FLOW
# Match Case (Python 3.10+)
match command:
    case "START": init()
    case "STOP": shutdown()
    case _: print("Unknown")

# Context Manager
with open("log.txt", "r") as file:
    content = file.read()
            
04_FUNCTIONAL_OPS
# Lambda Functions
add = lambda a, b: a + b

# Map / Filter
nums = [1, 2, 3, 4]
evens = list(filter(lambda x: x % 2 == 0, nums))

# *args and **kwargs
def stream(*data, **meta):
    print(data, meta)
            
05_OOP_ADVANCED
class Drone:
    # Class variable
    origin = "DarkSyntax"

    def __init__(self, model):
        self.model = model # Instance variable

    @classmethod
    def get_origin(cls): return cls.origin

    @property
    def label(self): return f"M-{self.model}"
            
06_ITERATORS
# Generators (Memory Efficient)
def data_stream():
    for i in range(1000):
        yield f"Packet_{i}"

stream = data_stream()
next(stream) # Packet_0
            
07_ASYNC_IO
import asyncio

async def fetch_data():
    await asyncio.sleep(1)
    return {"status": 200}

# Running the loop
# asyncio.run(fetch_data())
            
08_ERROR_HANDLING
try:
    raise ValueError("Override Error")
except ValueError as e:
    print(e)
finally:
    cleanup_system()