AttributeError: 'tuple' object has no attribute 'split' Any advice would be really helpful
AttributeError: 'tuple' object has no attribute 'split' Any advice would be really helpful
我现在刚开始学习基本的 python 编码,我正在使用视频教程来学习,我是 运行 IDLE Python 2.7。 12 Shell 并跟随讲师使用 IDLE 3.5.0 Shell。所以我遇到的问题是当我尝试使用即将出现的拆分方法时
>>> numbers = input("Enter your numbers, separated by commas: ")
Enter your numbers, separated by commas: 1,2,3
>>> numbers.split(",")
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
numbers.split(",")
AttributeError: 'tuple' object has no attribute 'split'
我真的不明白这是为什么。当他运行它时,数字会返回 ['1','2','3']。我确信这是非常基本的,但我将非常感谢您提供的任何帮助或建议。谢谢
您正在使用 python2,在本例中 input()
评估用户输入。在 python2 中,您应该使用 raw_input()
而不是 input()
也就是说,您真的应该使用 python 3(您的讲师正在使用)
word=raw_input("Test")
word.split()
print(word)
对 Python 2.X 使用 raw_input()
。它已在 Python 3.X.
中弃用
我现在刚开始学习基本的 python 编码,我正在使用视频教程来学习,我是 运行 IDLE Python 2.7。 12 Shell 并跟随讲师使用 IDLE 3.5.0 Shell。所以我遇到的问题是当我尝试使用即将出现的拆分方法时
>>> numbers = input("Enter your numbers, separated by commas: ")
Enter your numbers, separated by commas: 1,2,3
>>> numbers.split(",")
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
numbers.split(",")
AttributeError: 'tuple' object has no attribute 'split'
我真的不明白这是为什么。当他运行它时,数字会返回 ['1','2','3']。我确信这是非常基本的,但我将非常感谢您提供的任何帮助或建议。谢谢
您正在使用 python2,在本例中 input()
评估用户输入。在 python2 中,您应该使用 raw_input()
而不是 input()
也就是说,您真的应该使用 python 3(您的讲师正在使用)
word=raw_input("Test")
word.split()
print(word)
对 Python 2.X 使用 raw_input()
。它已在 Python 3.X.