Tag: Python 101

  • Python 101: 57 Built-in Functions

    Python 57 Built-in Functions Python 57 Built-in Functions Built-in Functions 内置函数 A abs() aiter() all() anext() any() ascii() B bin() bool() breakpoint() bytearray() bytes() C callable() chr() classmethod() compile() complex() D delattr() dict() dir() divmod() E enumerate() eval() exec() F filter() float() format() frozenset() G getattr() globals() H hasattr() hash()…

  • Python 101: The Difference Between Two Function Definitions in Python

    Understanding the differences between two seemingly similar function definitions in Python is crucial for avoiding unintended side effects and understanding Python’s handling of default arguments. Function Definition 1 def f(a, L=None): if L is None: L = [] L.append(a) return L Function Definition 2 def f(a, L=[]): L.append(a) return L…

  • Python 101: Exploring the Efficiency and Implementation of Python’s `enumerate()` Function

    The enumerate() function in Python is a built-in function that adds a counter to an iterable and returns it in the form of an enumerate object. This function is highly useful when you need to loop through an iterable and keep track of the index of each item. How enumerate()…

  • Python 101: Understanding the Python `range()` Function

    The range() function in Python generates a sequence of numbers. It’s commonly used for looping a specific number of times in for loops. While the range() function appears straightforward, its implementation is a bit more complex. Here’s a detailed look at how the range() function is implemented and how it…

  • Python 101: Understanding the Implementation of Python’s `match` Function

    Python’s match function is part of the re module, which provides support for regular expressions. The match function checks for a match only at the beginning of the string, while search checks for a match anywhere in the string. Here is a simplified explanation of how the match function works,…

  • Python 101: Unpacking Python’s Counter Class with A Detailed Look at Its Source Code and Functionality

    The Counter class in Python’s collections module is implemented in C for performance reasons. However, a simplified version in Python can help us understand its functionality and structure. Below is a detailed explanation of a basic version of Counter. Simplified Source Code for Counter from collections import defaultdict class Counter(dict):…

  • Python 101: `if not root:` vs `if root is None:`

    In Python, both if not root: and if root is None: are used to check if a variable is None, but they have subtle differences in their behavior and use cases: if not root: Behavior: This condition checks if root is "falsy." In Python, values like None, 0, False, empty…

  • Python 101: Python Unit Testing Using AAA

    Python 101: Python Unit Testing Using AAA

    Introduction to Python Unit Testing Using AAA Unit testing is a crucial part of software development that ensures individual components of your code work as expected. The AAA (Arrange, Act, Assert) pattern is a widely adopted structure for writing clear and maintainable tests. This guide will help you understand and…

  • Python 101: Python 35 keywords

    Python 35 keywords Keyword Definition Code Example Tips False Boolean value indicating false. is_student = False Use in conditional statements to represent a false state. None Represents the absence of a value or a null value. result = None Commonly used to initialize variables or indicate no result. True Boolean…

  • Python 101: Sets

    Python Sets https://www.w3schools.com/python/python_sets.asp In Python, a set is a collection of unique elements, and it is an unordered and unindexed collection of items. Set is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Tuple, and Dictionary, all with different…