简体   繁体   English

当我在Python控制台中运行此代码时,为什么会得到不同的结果?

[英]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中获取所需输出的方法:

Python 2 Python 2

>>> range(5,10)
[5, 6, 7, 8, 9]

Python 3 Python 3

>>> 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.

相关问题 为什么我在运行此代码时会收到错误代码? - Why am I getting an error code when I run this code? Python:为什么我得到不同的排序结果 - Python: Why am I getting different sorted results 在运行我的 selenium python 脚本时,我正在控制台中使用退出代码 0 完成处理,但我的结果没有显示 - On running my selenium python script, i am getting processed finished with exit code 0 in the console but my results are not showing up 为什么我的代码每次运行时都会产生不同的结果? (Python) - Why does my code generate different results each time i run it? (Python) 为什么我的 python 代码中出现 Traceback 错误 - Why am I getting Traceback error in my python code 为什么我的 python 代码出现值错误 - Why am I getting a Value error on my python code 当我的代码正确缩进时,为什么会出现IndentationError? - Why am I getting an IndentationError when my code is properly indented? 当我运行测试套件时,出现TypeError错误,我无法理解为什么 - When I run my test suite I am getting a TypeError I am not able to understand why 为什么我在调用总和 0 时在 python 中得到这个错误代码 - Why am i getting this error code in python when calling a sum of 0 为什么我使用不同的算法得到不同的引导结果? - Why am I getting different bootstrap results using different algorithms?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM