Amitabha@python 2019-09-17 16:01 采纳率: 0%
浏览 1591

TypeError: 'NoneType' object is not iterable到底时什么原因导致的,代码哪里有问题?已解决。

>>> values=list(range(1,11)).extend('Jack Queen King'.split(' '))
>>> suits='diamonds clubs hearts spades'.split(' ')
>>> deck=['%s of %s'%(v,s)for v in values for s in suits]
Traceback (most recent call last):
  File "<pyshell#42>", line 1, in <module>
    deck=['%s of %s'%(v,s)for v in values for s in suits]
**TypeError: 'NoneType' object is not iterable**
>>> values
>>> deck=['%s of %s'%(v,s)for v in list(range(1,11)).extend('Jack Queen King'.split(' ')) for s in 'diamonds clubs hearts spades'.split(' ')]
Traceback (most recent call last):
  File "<pyshell#44>", line 1, in <module>
    deck=['%s of %s'%(v,s)for v in list(range(1,11)).extend('Jack Queen King'.split(' ')) for s in 'diamonds clubs hearts spades'.split(' ')]
**TypeError: 'NoneType' object is not iterable**
>>> list3=list1
>>> list3
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ['Jack', 'Queen', 'King'], 'Jack', 'Queen', 'King']
>>> 'diamonds clubs hearts spades'.split(' ')
['diamonds', 'clubs', 'hearts', 'spades']
>>> deck1=[v for v in values]
Traceback (most recent call last):
  File "<pyshell#48>", line 1, in <module>
    deck1=[v for v in values]
**TypeError: 'NoneType' object is not iterable**

解决后的代码

>>> values=list(range(1,11))
>>> values
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> values.extend('Jack Queen King'.split(' '))#代码主要更改的部分
>>> values
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King']
>>> suits='diamonds clubs hearts spades'.split(' ')
>>> suits
['diamonds', 'clubs', 'hearts', 'spades']
deck=['%s of %s'%(v,s)for v in values for s in suits]
>>> deck
['1 of diamonds', '1 of clubs', '1 of hearts', '1 of spades', '2 of diamonds', '2 of clubs', '2 of hearts', '2 of spades', '3 of diamonds', '3 of clubs', '3 of hearts', '3 of spades', '4 of diamonds', '4 of clubs', '4 of hearts', '4 of spades', '5 of diamonds', '5 of clubs', '5 of hearts', '5 of spades', '6 of diamonds', '6 of clubs', '6 of hearts', '6 of spades', '7 of diamonds', '7 of clubs', '7 of hearts', '7 of spades', '8 of diamonds', '8 of clubs', '8 of hearts', '8 of spades', '9 of diamonds', '9 of clubs', '9 of hearts', '9 of spades', '10 of diamonds', '10 of clubs', '10 of hearts', '10 of spades', 'Jack of diamonds', 'Jack of clubs', 'Jack of hearts', 'Jack of spades', 'Queen of diamonds', 'Queen of clubs', 'Queen of hearts', 'Queen of spades', 'King of diamonds', 'King of clubs', 'King of hearts', 'King of spades']
  • 写回答

1条回答 默认 最新

  • zqbnqsdsmd 2019-09-18 19:17
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题