python - 执行简单循环时Python中的意外输出
问题描述
我有这个相当简单的循环
cities = ['Merano', 'Madrid', 'New York', 'Bangkok']
countries = ['Italy', 'Spain', 'USA']
for index, city in enumerate(cities):
print('This is index:', index)
print('This is city:', city)
print('The length of the list \'cities\' is: ', len(cities))
print(print('The length of the list \'countries\' is: ', len(countries)))
print(countries[index])
print(5 * '#')
我希望它会破裂。然而,我没想到的是这个输出。
This is index: 0
This is city: Merano
The length of the list 'cities' is: 4
The length of the list 'countries' is: 3
None
Italy
#####
This is index: 1
This is city: Madrid
The length of the list 'cities' is: 4
The length of the list 'countries' is: 3
None
Spain
....
从哪里来none
?我不print
这样做,也不执行我希望打印的东西......
解决方案
print(print('The length of the list \'countries\' is: ', len(countries)))
你在使用中使用了 print(print())
print('The length of the list \'countries\' is: ', len(countries))`
推荐阅读
- r - R - 如何将整数转换为位向量?
- python - 即使安装了软件包也会出错
- ruby-on-rails-3 - 如何修复 rake db:migrate 后自动编辑的 Rails Schema 文件
- r - 如何将多个提取的子集插入/合并到基于行中相同名称的数据集中
- laravel - 如何在验证的 after 函数中访问请求参数?
- selenium - 当 Protractor 测试远程运行时,浏览器 URL 不加载
- go - Type a type后,不能再混用
- postgresql - 如何重置表的存储参数
- reactjs - 你如何在反应中设置嵌套 css 的样式?
- javascript - 当我使用 JQuery.find 时,哪个是“选择”选项列表的 jQuery 选择器