首页 > 解决方案 > TypeError:一元+的错误操作数类型:'str'当我认为代码正确时

问题描述

character_age = "13"
character_name = "lado"
print(   + character_name +    " really like coding")
print( " but she didnt learn to type until "  + character_age +  " years old. ")

当出现错误时,我试图在 python 中学习变量

PS D:\freecodecamp> & C:/Users/admin/AppData/Local/Programs/Python/Python39/python.exe d:/freecodecamp/2.py
Traceback (most recent call last):
  File "d:\freecodecamp\2.py", line 6, in <module>
    print(+_character_name+   " really like coding, ")
TypeError: bad operand type for unary +: 'str'

标签: python

解决方案


+您的第一个打印声明中有一个额外的内容。用这个:print(character_name + " really like coding")


推荐阅读