Here are some common errors in Python, along with examples:
if True
print("Hello")
SyntaxError: invalid syntax:) is missing at the end of the if statement.def my_function():
print("Hello, World!")
IndentationError: expected an indented blockprint statement should be indented under the function definition.print(x)
NameError: name 'x' is not definedx is used before it is defined.result = "Hello" + 5
TypeError: can only concatenate str (not "int") to strmy_list = [1, 2, 3]
print(my_list[5])
IndexError: list index out of range
my_dict = {"name": "Alice"}
print(my_dict["age"])
KeyError: 'age''age' does not exist in the dictionary.my_list = [1, 2, 3]
my_list.append(4)
my_list.push(5)
AttributeError: 'list' object has no attribute 'push'push method does not exist for lists in Python; you should use append.int("Hello")
ValueError: invalid literal for int() with base 10: 'Hello'"Hello" cannot be converted to an integer.result = 10 / 0
ZeroDivisionError: division by zero import non_existent_module
ImportError: No module named 'non_existent_module'Understanding these common errors can help you debug your code more efficiently. Each error comes with a message that can guide you toward fixing the issue.