Stackoverflow 精选(Python 相关)



What does the yield keyword do in Python?
Does Python have a ternary conditional operator?
What does if __name__ == "__main__" do?
Python - append vs. extend
How do I pass a variable by reference?
Explain Python’s slice notation
What does ** (double star) and * (star) do for Python parameters?
Determine the type of an object?


What is the difference between @staticmethod and @classmethod in Python?
Understanding Python super() with __init__() methods
Difference between __str__ and __repr__ in Python
Static class variables in Python
Static methods in Python?


How can I make a chain of function decorators in Python?
Using global variables in a function other than the one that created them
Python join, why is it string.join(list) instead of list.join(string)?


“Least Astonishment” in Python: The Mutable Default Argument


Calling an external command in Python
How to check whether a file exists using Python?
How can I merge two Python dictionaries in a single expression?
Sort a Python dictionary by value
How to check if a directory exists and create it if necessary?
Best way to check if a list is empty
How to list all files of a directory in Python
How can I represent an ‘Enum’ in Python?
Catch multiple exceptions in one line (except block)
Print in terminal with colors using Python?
Making a flat list out of list of lists in Python
How do you split a list into evenly sized chunks in Python?
How do you read from stdin in Python?
Python string formatting: % vs. .format
How do I randomly select an item from a list using Python?
Converting string into datetime

Advanced Topics

What is a metaclass in Python?
What is for?
Why is reading lines from stdin much slower in C++ than Python?