Python random function

前端 未结 9 1099
后悔当初
后悔当初 2020-12-10 03:26

I\'m having problems with Python\'s import random function. It seems that import random and from random import random are importing different thing

9条回答
  •  抹茶落季
    2020-12-10 04:18

    import random imports the random module, which contains a variety of things to do with random number generation. Among these is the random() function, which generates random numbers between 0 and 1.

    Doing the import this way this requires you to use the syntax random.random().

    The random function can also be imported from the module separately:

    from random import random
    

    This allows you to then just call random() directly.

提交回复
热议问题