How to reverse a string (x) in Python?
x[::-1]
List vs. Tuple
Definition:
Lists are mutable sequences, while tuples are immutable sequences.
List Comprehensions
Definition:
A concise syntax for creating lists from iterables with optional conditions.
e.g., Increment item when <9
[item+1 for item in items if item<9]
Generators
Definition:
Functions that use yield to produce a sequence of values lazily.
GIL (Global Interpreter Lock)
Definition:
A mutex in CPython preventing multiple native threads from executing Python bytecodes simultaneously.
Decorator
Definition:
A callable (function or class) that takes another function and extends or modifies its behavior.
__init__ vs. __new__
Definition:
__init__ initializes an instance after it’s created; __new__ actually creates the instance (rarely overridden).
__init__ is used for most initialization tasks.
__new__ is useful for customizing the creation of immutable types or singletons.
Python Memory Management
Definition:
Uses reference counting and a cyclic garbage collector to free unreachable objects.