Assign a range to a variable (Python)

后端 未结 3 998
醉酒成梦
醉酒成梦 2021-01-12 16:00

Whenever I try to assign a range to a variable like so:

Var1 = range(10, 50)

Then try to print the variable:

Var1 = range(1         


        
3条回答
  •  星月不相逢
    2021-01-12 16:31

    Thats because range returns a range object in Python 3. Put it in list to make it do what you want:

    >>> Var1 = range(10, 50)
    >>> print(list(Var1))
    [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,  
    32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49]
    >>>
    

提交回复
热议问题