Skip to content

Instantly share code, notes, and snippets.

@samoshkin
Created April 5, 2023 20:02
Show Gist options
  • Save samoshkin/a753c028b6cb6c8865a85bbc02f1a587 to your computer and use it in GitHub Desktop.
Save samoshkin/a753c028b6cb6c8865a85bbc02f1a587 to your computer and use it in GitHub Desktop.
Statements about Python

Statements describing Python as a language

Interpreted: Python is an interpreted language, which means that the source code is translated and executed line-by-line at runtime, rather than being compiled to machine code beforehand.

Dynamic type system: Python uses a dynamic type system, which means that variable types are determined at runtime and can change during the execution of a program.

Garbage-collected: Python automatically manages memory allocation and deallocation using garbage collection, which frees developers from having to manually manage memory in their code.

Indentation-based syntax: Python uses indentation to define code blocks, making the code more readable and less cluttered with braces or other delimiters.

Batteries-included philosophy: Python has a large standard library that provides a wide range of functionality out of the box, reducing the need for external libraries and simplifying development.

Object-oriented: Python supports object-oriented programming, allowing developers to create and work with objects, classes, and inheritance to model complex systems and manage code complexity.

Functional programming features: Python also includes functional programming features such as lambda functions, map, filter, and reduce, offering developers more flexibility in their coding style.

Cross-platform compatibility: Python is available on multiple platforms, including Windows, macOS, Linux, and various Unix systems, making it suitable for developing cross-platform applications.

Extensible: Python can be extended with C, C++, or other languages, allowing developers to write high-performance or low-level code when needed, while still benefiting from Python's ease of use.

Large ecosystem: Python has a large and active community that contributes to a rich ecosystem of libraries and frameworks, making it easy to find tools and resources for almost any task.

Python weaknesses and pitfalls

Runtime errors: Due to its dynamic type system, some type errors can only be detected at runtime, which may lead to unexpected issues and bugs that are harder to catch and fix during development. Python's dynamic type system may make it harder to enforce strict typing rules and catch type-related issues early in the development process, which can be especially problematic in large or complex codebases.

Performance: Python's interpreted nature and dynamic typing make it slower than compiled languages like C, C++, or Java, which can be a limiting factor for certain high-performance or time-sensitive applications.

Global Interpreter Lock (GIL): Python's GIL limits the execution of multiple threads in a single process, which can lead to suboptimal utilization of multi-core processors and hinder performance in certain types of concurrent or parallel applications.

Memory consumption: Python's dynamic typing and garbage collection can lead to higher memory consumption compared to statically-typed languages, which may be an issue in memory-constrained environments.

Limited mobile development support: Python is not as popular or well-suited for mobile application development as languages like Swift, Kotlin, or Java, leading to fewer resources and tools available for this purpose.

Immutable built-in data structures: Certain built-in data structures like tuples and strings are immutable, which can sometimes lead to less efficient operations, such as creating new objects instead of modifying existing ones.

Indentation-based syntax: While Python's indentation-based syntax improves code readability, it can also be a source of confusion or frustration for developers coming from languages that use braces or other delimiters to define code blocks.

Two major versions: Although Python 3 is now the standard version, Python 2 still has a significant presence, causing potential compatibility issues and confusion for developers working with different versions or libraries.

Limited native GUI support: Python does not have a built-in GUI library in its standard library like Java's Swing or C#'s WPF, and while third-party libraries like Tkinter, PyQt, and Kivy are available, they may not be as polished or feature-rich as native GUI libraries in other languages.

Reasons of having bigger memory footprint:

  • In Python, variables are dynamically typed, which means that the type of a variable can change during runtime. This flexibility comes at a cost because Python needs to store additional information about the type of each variable, rather than just the value itself. This overhead can lead to increased memory usage compared to statically-typed languages, where the type information is determined at compile-time, and the memory layout is more efficient.
  • Objects and reference counting: In Python, everything is an object, even simple data types like integers and strings. The memory overhead for objects can be significant, especially for small objects or large collections of objects. Python uses reference counting to keep track of the number of references to an object, which also adds some memory overhead.
  • Garbage collection: Python uses a garbage collector to automatically reclaim memory occupied by objects that are no longer in use. While garbage collection is convenient and helps to prevent memory leaks, it can also result in higher memory usage because the memory occupied by unused objects is not immediately freed. Instead, the garbage collector runs periodically and frees memory in batches.
  • Memory fragmentation. The dynamic allocation and deallocation of memory for objects in Python can lead to memory fragmentation, where the memory is divided into small, non-contiguous blocks. Fragmentation can result in inefficient memory usage, as the free memory blocks might be too small to accommodate new objects, causing Python to request more memory from the operating system even when there is theoretically enough free memory available.

Use cases

Web development: With powerful web frameworks like Django, Flask, and Pyramid, Python is an excellent choice for creating web applications, from simple sites to complex web services and APIs.

Data science and machine learning: Python's extensive ecosystem of libraries and tools, including NumPy, pandas, Matplotlib, TensorFlow, and scikit-learn, makes it a top choice for data analysis, visualization, and machine learning tasks.

Scientific computing: Python is popular in the scientific community, thanks to libraries like SciPy, SymPy, and Jupyter that provide support for mathematical, statistical, and symbolic computing.

Scripting and automation: Python's readability, ease of use, and extensive standard library make it a great language for scripting, automating tasks, and creating command-line tools.

Educational purposes: Python's simple syntax and readability make it an excellent language for teaching programming concepts to beginners, and it is widely used in educational settings, from schools to universities.

Network programming: Python's standard library includes modules for working with sockets, protocols, and network services, making it a suitable choice for network programming and building network-related tools.

Cybersecurity and penetration testing: Python is widely used in the cybersecurity field for creating tools, automating tasks, and performing penetration testing due to its flexibility and extensive library support.

Not so good or bad use cases:

  • Desktop application development, Python can be used to create cross-platform desktop applications using libraries like Tkinter, PyQt, or Kivy, although it may not be the first choice for performance-critical or resource-intensive applications.
  • performance-critical applications, or situations where memory constraints or native GUI support are important factors
  • mobile app development
  • large and complex apps where you would rather choose statically typed language
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment