简体   繁体   中英

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. When I run this code in my Python console I get these result:

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

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

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM