Επιστροφή στην Εργαλειοθήκη

Python Power-up

Συντομεύσεις και δομές για γρήγορο Development.

Data Structures

# List Comprehension
nums = [x*x for x in range(10)]
# Dictionary
data = {"id": 1, "val": "AI"}
# Unpacking
a, b = [10, 20]

Useful Functions

# Map & Filter
f = filter(lambda x: x > 0, nums)
# Zip
for i, j in zip(lst1, lst2):
# Enumerate
for idx, val in enumerate(data):

File I/O

# Context Manager
with open('f.txt', 'r') as f:
  content = f.read()
# JSON handling
import json
d = json.loads(str_data)

OOP & Decorators

# Class setup
class AI:
  def __init__(self):
    self.active = True
# Decorator
@timer
def task(): pass