List of Python Articles
Contents
- Environment information and settings
- Coding standards and conventions
- pip (package-management system)
- Imports
- Handling exceptions, warnings, and assertions
- Comments and docstrings
- Command line arguments
- Standard inputs and outputs
- Types and classes
- Operators
- Functions and arguments
for
andwhile
loopsif
statements- Lists (
list
) - Tuples (
tuple
) - Sets (
set
) - Dictionaries (
dict
) - Strings (
str
) - Numerics (
int
adnfloat
) - Mathematics
- Algorithms
- Files and directories
- Dates and times
- Other built-in functions
- Other modules/libraries
Environment information and settings
- Check Python Version on Command Line and in Scripts
- Get the OS Name and Version in Python
- Get and Change the Current Working Directory in Python
- Get the Path of the Current File (Script) in Python:
__file__
- Get, Set, and Delete Environment Variables in Python: os.environ
- Get/Set the Recursion Limit in Python: sys.getrecursionlimit, sys.setrecursionlimit
Coding standards and conventions
- Python Indentation Rules
- Valid Variable Names and Naming Rules in Python
- Keywords and Reserved Words in Python
- Write a Long String on Multiple Lines in Python
- Method Chaining Across Multiple Lines in Python
pip (package-management system)
- How to Use pip (Install, Update, Uninstall Packages)
- How to Install Python Packages with pip and requirements.txt
- How to List Installed Python Packages with pip list/freeze
- Check the Versions of Python Packages
Imports
- How to Import Modules, Packages, Functions in Python
- Check and Add the Module Search Path in Python: sys.path
- What is
if __name__ == '__main__'
in Python
Handling exceptions, warnings, and assertions
- Try, except, else, finally in Python (Exception handling)
- The assert Statement in Python
- How to Ignore Warnings in Python
- The pass Statement in Python
Comments and docstrings
- How to Write a Comment and Comment Out Lines in Python
- Python Docstring Formats (Styles) and Examples
Command line arguments
- Command Line Arguments in Python: sys.argv, argparse
- Handle Boolean Arguments with argparse in Python
Standard inputs and outputs
Types and classes
- Get and Check the Type of an Object in Python: type(), isinstance()
- Convert Between bool (True/False) and Other Types in Python
- Check Subclass and Superclass in Python: issubclass,
__bases__
- Duck Typing in Python: hasattr() and Abstract Base Class
- None in Python
Operators
- Arithmetic Operators in Python (+, -, , /, //, %, *)
- Boolean Operators in Python (and, or, not)
- Bitwise Operators in Python (AND, OR, XOR, NOT, SHIFT)
- Difference Between the == and is Operators in Python
- Chained Comparison (a < x < b) in Python
- Multiple Assignment in Python
Functions and arguments
- Define and Call Functions in Python (def, return)
*args
and**kwargs
in Python (Variable-Length Arguments)- Default Parameter Values in Python Functions
- Expand and Pass a List and Dictionary As Arguments in Python
- How to Return Multiple Values from a Function in Python
- Lambda Expressions in Python
for
and while
loops
- Python for Loop (With range, enumerate, zip)
- Use enumerate() and zip() Together in Python
- Break Out of Nested Loops in Python
- Python while Loop (Infinite Loop, break, continue)
if
statements
Lists (list
)
Basics
- List vs. Array vs. numpy.ndarray in Python
- Initialize a List of Any Size with Specific Values in Python
- List Comprehensions in Python
- Apply a Function to Items of a List in Python: map()
- Filter (Extract/Remove) Items of a List with in Python: filter()
- Get the Size (Length, Number of Items) of a List in Python
- Compare Lists in Python
- The in Operator in Python (for List, String, Dictionary)
- Convert Between a List and a Tuple in Python
Adding and removing items
- Add an Item to a List in Python: append, extend, insert
- Remove an Item from a List in Python: remove, pop, clear, del
Extracting and replacing items
- Find the Index of an Item in a List in Python
- How to Slice a List, String, and Tuple in Python
- Extract, Replace, Convert Elements of a List in Python
- Extract and Replace Elements That Meet the Conditions of a List of Strings in Python
- Get the N-Largest/Smallest Elements from a List in Python
- Random Sample from a List in Python: random.choice, sample, choices
- How to Start enumerate() at 1 in Python
- Get Elements from Multiple Lists in Python: zip()
Sorting, reversing, and shuffling lists
- Sort a List, String, Tuple in Python: sort, sorted
- How to Use the key Argument in Python (sorted, max, etc.)
- Sort a List of Numeric Strings in Python
- Reverse a List, String, Tuple in Python: reverse, reversed
- Shuffle a List, String, Tuple in Python: random.shuffle, sample
- Swap Values in a List or Values of Variables in Python
- Sort a 2D List in Python
- How to Transpose a List of Lists (2D List) in Python
- How to Flatten a List of Lists in Python
- Convert 1D Array to 2D Array in Python (numpy.ndarray, list)
Handling duplicate items
- Remove/Extract Duplicate Elements from List in Python
- Check If a List Has Duplicates in Python
- Extract Common/Non-common/Unique Elements from Multiple Lists in Python
- GROUP BY in Python: itertools.groupby
Other list operations
- Shallow and Deep Copy in Python: copy(), deepcopy()
- Convert a List of Strings and a List of Numbers to Each Other in Python
- Count Elements in a List in Python: collections.Counter
- Cartesian Product of Lists in Python: itertools.product
Tuples (tuple
)
- Add, Update, Remove Tuple Items in Python
- A Tuple with One Element Requires a Comma in Python
- How to Unpack a Tuple or List in Python
Sets (set
)
Dictionaries (dict
)
- Create a Dictionary in Python: {}, dict(), Dict Comprehensions
- Add and Update an Item in a Dictionary in Python
- Merge Dictionaries in Python
- Remove an Item from a Dictionary in Python: pop, popitem, clear, del
- Add an Item If the Key Does Not Exist in dict in Python: setdefault
- Check If a Key/Value Exists in a Dictionary in Python
- Get a Value from a Dictionary by Key in Python
- Get Keys from a Dictionary by Value in Python
- Iterate Over Dictionary Keys, Values, and Items in Python
- Change a Key Name in a Dictionary in Python
- Swap Keys and Values in a Dictionary in Python
- Get Maximum/Minimum Values and Keys in Python Dictionaries
- Set Operations on Multiple Dictionary Keys in Python
- Extract Specific Key Values from a List of Dictionaries in Python
- Sort a List of Dictionaries by the Value of the Specific Key in Python
Strings (str
)
Basics
- Create a String in Python: Single/Double/Triple Quotes, str()
- Get the Length of a String (number of Characters) in Python
- Concatenate Strings in Python: + Operator, join, etc.
- Replace Strings in Python: replace(), translate(), and Regex
- Split a String in Python (Delimiter, Line Breaks, Regex)
- Search for a String in Python (Check If a Substring Is Included/Get a Substring Position)
- String Comparison in Python (Exact/Partial Match, etc.)
- Extract a Substring from a String in Python (Position, Regex)
- Remove a Substring from a String in Python
- Count Characters or Substrings in a String in Python
- Handle Line Breaks (Newlines) in Strings in Python
- Uppercase and Lowercase Strings in Python (Conversion and Checking)
- Raw Strings in Python
Format
- Format Strings and Numbers in Python: format()
- How to Use f-strings in Python
- Pad Strings and Numbers with Zeros in Python (Zero-padding)
- Right-justify, Center, Left-justify Strings and Numbers in Python
Converting to numeric values
- Convert Binary, Octal, Decimal, and Hexadecimal in Python
- Convert a String to a Number (int, float) in Python
- Check If a String Is Numeric, Alphabetic, Alphanumeric, or Ascii
Regular expressions (Regex)
Other string operations
- Convert Between Unicode Code Point and Character: chr, ord
- Wrap and Truncate a String with textwrap in Python
Numerics (int
adn float
)
- Round Numbers in Python: round(), Decimal.quantize()
- Round Up/Down Decimals in Python: math.floor, math.ceil
- Get Absolute Values in Python: abs(), math.fabs()
- Generate Random Numbers (int and float) in Python
- Get Quotient and Remainder in Python: divmod()
- Check If a Number Is an Integer in Python
- Get the Fractional and Integer Parts in Python: math.modf()
- Integer (int) Has No Max Limit in Python 3
- Maximum and Minimum float Values in Python
- Check If the Floating Point Numbers Are Close in Python: math.isclose
- Infinity (inf) in Python
- What is nan in Python (float('nan'), math.nan, np.nan)
- Sign Function in Python: sign/signum/sgn, copysign
- Count the Number of 1 Bits in Python: int.bit_count
Mathematics
- Fractions (Rational Numbers) in Python
- Complex Numbers in Python
- Set Operations in Python (Union, Intersection, Symmetric Difference)
- Trigonometric Functions in Python: sin, cos, tan, arcsin, arccos, arctan
- Power and Logarithmic Functions in Python: exp, log, log10, log2
- Find GCD and LCM in Python: math.gcd(), lcm()
- Calculate Mean, Median, Mode, Variance, Standard Deviation in Python
- Cumulative Calculations in Python: itertools.accumulate()
Algorithms
Files and directories
Reading, writing, and creating files
Creating directories
Deleting, moving, coping files and directories
- Delete a File/Directory in Python: os.remove, shutil.rmtree
- Move a File/Directory in Python: shutil.move
- Copy a File/Directory in Python: shutil.copy, shutil.copytree
Checking existence, size, and timestamp
- Check If a File/Directory Exists in Python: os.path.exists, isfile, isdir
- Get the File/Directory Size in Python: os.path.getsize
- Get File Timestamp in Python: os.stat, os.path.getmtime
Path manipulations
- Get the Filename, Directory, Extension from a Path String in Python
- Get a List of File and Directory Names in Python
- How to Use glob() in Python
- How to Use pathlib in Python
CSV, JSON, and ZIP
- Read and Write CSV Files in Python
- Load, Parse, Serialize JSON Files and Strings in Python
- Zip and Unzip Files in Python: zipfile, shutil
Dates and times
- Handle Date and Time in Python: datetime
- Get the Current Date and Time in Python: datetime.now, date.today
- Measure Elapsed Time and Time Differences in Python
- Convert Between Isoformat String and datetime in Python
- Convert Unix Time (Epoch Time) to and from datetime in Python
- Create Calendar as text, HTML, List in Python
- Get the Number of Days and Weeks in a Month in Python
- Determine, Count, and List Leap Years in Python
Other built-in functions
- How to Use range() in Python
- How to Use len() in Python
- How to Use all() and any() in Python
- List Built-in Objects in Python:
dir(__builtins__)
Other modules/libraries
- Infinite Iterators in Python: itertools.count, cycle, repeat
- The operator Module in Python: itemgetter, attrgetter, methodcaller
- Measure Execution Time with timeit in Python
- Guess MIME Type from Filename/URL with mimetypes in Python
- Copy and Paste Text to the Clipboard with pyperclip in Python
- Detect and Read Barcodes and QR Codes with ZBar in Python