TypeError: __init__() missing 1 required positional argument: 'name'
You’re calling a function without all the required arguments.
Fix 1: Pass all required arguments
class User:
def __init__(self, name, email):
self.name = name
self.email = email
# ❌ Missing email
user = User("Alice")
# ✅ Pass all arguments
user = User("Alice", "alice@example.com")
Fix 2: Forgot self in method call
class Calculator:
def add(self, a, b):
return a + b
# ❌ Calling on the class, not an instance
Calculator.add(1, 2)
# ✅ Create an instance first
calc = Calculator()
calc.add(1, 2)
Fix 3: Add default values
def greet(name, greeting="Hello"):
return f"{greeting}, {name}!"
greet("Alice") # Works — greeting defaults to "Hello"