[英]Why I am getting different results when I run this code in my Python console?
I am working on a simple range code example: 我正在研究一个简单的范围代码示例:
range(5, 10)
Output should be: [5, 6, 7, 8, 9]
, according to the website I'm working on and seen videos on. 输出应为:
[5, 6, 7, 8, 9]
,根据我正在使用的网站并查看过的视频。 When I run this code in my Python console I get these result: 当我在Python控制台中运行此代码时,得到以下结果:
>>> range (5,10)
0
1
2
3
4
5
6
7
8
9
What am I doing wrong? 我究竟做错了什么?
Here's how to get the output you want, in Python 2 and Python 3: 以下是在Python 2和Python 3中获取所需输出的方法:
>>> range(5,10)
[5, 6, 7, 8, 9]
>>> list(range(5,10))
[5, 6, 7, 8, 9]
The tutorial you're following is probably for Python 2 but your question is tagged Python 3, are you sure this is the right tutorial for you? 您正在关注的教程可能是针对Python 2的,但您的问题被标记为Python 3,您确定这是适合您的教程吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.