⤳ List comprehension is a programming technique to create a new list based on an existing list. This quick guide explores three approaches to JavaScript list comprehension (a.k.a array comprehension). Programmers use list or array comprehension for two reasons: List comprehension is usually available as a language construct in ...
⤳ One of the most common tasks when working with variables in Python is to return a default value if a variable (or a dictionary item) is None or if it doesn’t even exist. This quick guide explores four methods of returning a default value if ...
⤳ The Python error “ValueError: I/O operation on closed file” happens when you try to do I/O operations (read, write, etc.) on a file that’s already been closed. Here’s what the error looks like: This quick guide explains why this error happens and how to fix ...
⤳ When working with strings in JavaScript, it’s important to check if a variable is a string before performing any string-related operations – specially when you get the value from an API . This quick guide explores four methods for checking if a variable is a ...
⤳ Python __new__() method is static method (a.k.a magic or dunder method) that gives the programmer more control over how a specific class (cls) is instantiated. This quick guide explains the __new__() method and how and when to use it. How does the Python __new__() method ...
⤳ Python raises “SyntaxError: unterminated triple-quoted string literal” when you use a pair of triple quotes (""" or ''') around a multi-line string literal, but the ending part is missing. Here’s what the error looks like on Python version 3.11: On the other hand, the error ...
⤳ Python raises the error “SyntaxError: ‘return’ outside function” once it encounters a return statement outside a function. Here’s what the error looks like: Based on Python’s syntax & semantics, a return statement may only be used in a function to return a value to the caller. However, if – ...
⤳ 🚫 SyntaxError: positional argument follows keyword argument Python raises the “SyntaxError: positional argument follows keyword argument” error if you place one or more keyword arguments (e.g., age=35, name=John) before your positional arguments (e.g., 35, John) in a function call. Based on Python syntax, keyword arguments must follow positional arguments ...
⤳ The Python error “SyntaxError: Missing parentheses in call to ‘print’ …” occurs when you use an old-style print statement (e.g., print 'some value') in Python 3. This not so short error message looks like this: As the error explains, from version 3, print() is a ...
⤳ The error “SyntaxError: invalid non-printable character” in Python happens once Python encounters an invalid non-printing character (according to Python’s syntax) in your statements. Non-printing characters might not be visible in your code editor, and you might not notice them until you run the code. Having characters such as ...
⤳ The error “SyntaxError: invalid character” occurs once Python encounters an invalid character (according to Python’s syntax) in a statement. You may have invalid characters in a line of code if: Here’s what the error message looks like: This error also indicates which character causes the ...
⤳ Python raises “SyntaxError: unterminated string literal” when a string value doesn’t have a closing quotation mark. This syntax error usually occurs owing to a missing quotation mark or an invalid multi-line string. Here’s what the error looks like on Python version 3.11: On the other ...
⤳ Python raises “SyntaxError: EOL while scanning string literal” error when it reaches the end of the line, yet it hasn’t encountered the expected closing quotation mark (' or ") of a string literal – on the other hand the string literal isn’t properly closed. This ...
⤳ Python raises “SyntaxError: cannot assign to expression here. Maybe you meant ‘==’ instead of ‘=’?” when you assign a value to an expression. On the other hand, this error occurs if an expression is the left-hand side operand in an assignment statement. Additionally, Python provides ...
⤳ Python raises “SyntaxError: cannot assign to literal here. Maybe you meant ‘==’ instead of ‘=’?” when you assign a value to a literal (e.g., 12, '49.5', 'Sally'). On the other hand, this error occurs if a literal value is the left-hand side operand in a ...