Operation applied to an object of the wrong type.
A TypeError is raised when an operation or function is applied to an object of an inappropriate type. Python is dynamically typed, but it still enforces certain type rules at runtime. For example, you cannot concatenate a string and an integer directly.
This happens when you try to perform an operation that isn't supported for the given type(s). Common causes include: mixing strings and numbers in arithmetic/concatenation, passing wrong argument types to functions, calling non-callable objects, or iterating over a non-iterable.
1name = "Alice"2age = 303 4# Trying to concatenate a string and an integer directly5message = "Hello, my name is " + name + " and I am " + age + " years old."6print(message)1name = "Alice"2age = 303 4# Fix 1: Convert the integer to a string explicitly5message = "Hello, my name is " + name + " and I am " + str(age) + " years old."6print(message)7 8# Fix 2: Use an f-string (preferred, more readable)9message = f"Hello, my name is {name} and I am {age} years old."10print(message)Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
On line 5, Python tries to concatenate the integer `age` (30) with surrounding strings using the `+` operator. Python does not implicitly convert types during string concatenation, so it raises `TypeError: can only concatenate str (not "int") to str`.