Print a list in reverse order with range()?

前端 未结 19 786
长发绾君心
长发绾君心 2020-11-30 17:09

How can you produce the following list with range() in Python?

[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
19条回答
  •  心在旅途
    2020-11-30 17:43

    You can do printing of reverse numbers with range() BIF Like ,

    for number in range ( 10 , 0 , -1 ) :
        print ( number ) 
    

    Output will be [10,9,8,7,6,5,4,3,2,1]

    range() - range ( start , end , increment/decrement ) where start is inclusive , end is exclusive and increment can be any numbers and behaves like step

提交回复
热议问题