Common Questions
This is a list of common questions within the Python tag. Each question includes some canonical SO questions that can be used to close-vote any new questions that match. If you have any suggestions then please come see us in chat.
- Each space separated value is a separate search term.
- Terms are ANDed together.
- [Brackets] indicate a tag term.
is:draft
shows only draft posts.is:community
shows only community posts.
A typo like |
You get this error when you try to call |
A type hint that tries to use a not-yet-defined name will throw a NameError. |
Most commonly, this is a Windows user forgetting to put |
User tries to read data from a file which is clearly not in UTF-8, but fails to understand that this is what the error message means. |
When inside a Jinja expression, you reference the variables directly, rather than within nested curly braces. |
When using |
The splat operator (*) can be used to unpack variables from a container when calling a function. |
A function using |
From Python 3 onwards reduce must be imported from functools. |
|
Choosing elements from a sequence with a non-uniform probability. |
|
How does splat unpacking work for sequences (*) and dictionaries (**). |
Seeing something like |
A docstring is a the first unassigned string in a function, class, or module declaration. |
The terminology makes finding a canonical “That’s a list / dict / etc. comprehension” question hard. |
Why doesn’t my Python execute in this rendered JavaScript? |
|
The representation of a string with backslashes can sometimes throw a user as they are escaped. |
If a function does not return a value then it automatically returns |
The recursive call in a function misses a |
Python parses 2. as the float 2.0, this can cause troubles when trying to use methods on integers. |
Testing against multiple values using boolean operators, sometimes people think booleans work like English grammar. |
The OP expects a variable in their callback lambdas to have the value it had when the function was created, instead it has the current value at calling time. |
Coming from other languages people might try to use |
Strings are immutable, so methods on the string that alter the string return a new value. Typically beginners forget this and call str.upper() or str.lower() or str.title() or str.replace() or str.strip() without assigning the new string back to the variable. |
|
It’s a hardware issue. |
The way Python handles newlines on Windows can result in blank lines appearing between rows when using |