def print_first_word(words):
"""Prints the first word after popping it off."""
print ( words.pop(0))
sentence = "All god\tthings come to those who weight."
print_first_word(sentence)
报错 AttributeError: 'str' object has no attribute 'pop'
def print_first_word(words):
"""Prints the first word after popping it off."""
print ( words.pop(0))
sentence = "All god\tthings come to those who weight."
print_first_word(sentence)
报错 AttributeError: 'str' object has no attribute 'pop'
提示内容翻译一下就知道了:
'str' 类型的对象没有 'pop' 这个属性
函数本身的设计上应该是要传入列表,但是你传入的 sentence
明显是一个字符串,你可以修改函数使它可以处理字符串,也可以修改传入的参数把它变成列表。
3 回答3.1k 阅读✓ 已解决
2 回答1.9k 阅读✓ 已解决
2 回答1.3k 阅读✓ 已解决
2 回答1.8k 阅读✓ 已解决
4 回答1.9k 阅读
3 回答1.7k 阅读
1 回答1.4k 阅读✓ 已解决