TypeError: can only concatenate str (not "int") to str
时间: 2023-11-21 14:58:45 浏览: 28
This error occurs when you try to concatenate a string and an integer using the + operator. In Python, you can only concatenate two strings using the + operator, not a string and an integer.
For example:
```
age = 25
print("I am " + age + " years old.")
```
This will result in a TypeError because you are trying to concatenate a string ("I am ") and an integer (25).
To fix this error, you need to convert the integer to a string before concatenating it with the string. You can do this using the str() function.
For example:
```
age = 25
print("I am " + str(age) + " years old.")
```
This will convert the integer age to a string using the str() function, allowing it to be concatenated with the string "I am ".