Python notes #1 (A Comprehensive Introduction to Python)

post-title

Python’s key features

  • Python is dynamically typedinterpreted, and supports multiple programming paradigms (OOPfunctionalprocedural). It has a large standard library and automatic memory management.

Python memory management

  • Python uses a private heap for memory management and has built-in garbage collection using reference counting and cyclic garbage collection.

Deep copy and shallow copy

  • shallow copy creates a new object but references the original elements, while a deep copy creates a completely independent copy of the original object and its elements.

Global Interpreter Lock (GIL)

  • GIL is a mutex in CPython that allows only one thread to execute at a time, limiting true parallel execution in multi-threaded programs.

Python dynamic typing handling

  • Python determines variable types at runtime, making development faster but potentially leading to runtime errors if types are misused.

CPython and Python’s different implementations

  • CPython is the default interpreter, PyPy offers JIT compilation for speed, Jython runs on the JVM, and IronPython integrates with .NET.
  • CPython is the default and most widely used implementation of Python, written in C. It compiles Python code into bytecode and executes it using a stack-based virtual machine. CPython includes a built-in garbage collector and follows the Global Interpreter Lock (GIL), which restricts true parallel execution in multi-threaded programs. It is the reference implementation of Python, meaning all other implementations (like PyPy, Jython, and IronPython) aim for compatibility with CPython.

Python’s exception handling

  • Python uses try-except-finally blocks to catch and handle exceptions, preventing program crashes and enabling graceful error handling.
Top