Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 为什么我得到“不支持的操作数类型错误”?_Python 3.x - Fatal编程技术网

Python 3.x 为什么我得到“不支持的操作数类型错误”?

Python 3.x 为什么我得到“不支持的操作数类型错误”?,python-3.x,Python 3.x,我在编码时遇到了这个错误,我不知道它是什么意思 line 59, in <module> filename=class_name + ".csv" TypeError: unsupported operand type(s) for +: 'int' and 'str' class_name是一个int。您可以在此处指定它: class_name=int(input("Are you in class 1, 2 or 3? ")) 但是,不能连接整数和字符串,因此必须先将

我在编码时遇到了这个错误,我不知道它是什么意思

line 59, in <module>
    filename=class_name + ".csv"
TypeError: unsupported operand type(s) for +: 'int' and 'str'
class_name是一个int。您可以在此处指定它:

class_name=int(input("Are you in class 1, 2 or 3? "))
但是,不能连接整数和字符串,因此必须先将int转换为str:

因此,您在输入时正确地将类_名称强制转换为int,因此现在它是int类型。csv是一种sstr类型。您可以选择filename=strclass\u name+.csv或filename={}.csv.formatclass\u name
class_name=int(input("Are you in class 1, 2 or 3? "))
filename= str(class_name) + ".csv"