The use of import in Python language is very simple, just use the import module_name statement to import. Here I mainly write about the essence of "import".
The import declaration combines two operations; it searches the named module and then binds the search results to the name in the local scope.
random() method returns a randomly generated real number, which is in the range [0,1). (Recommended learning: Python video tutorial)
The following is the syntax of the random() method:
import random random.random()
Note: random() cannot be directly To access, you need to import the random module and then call the method through the random static object.
Example
#!/usr/bin/python # -*- coding: UTF-8 -*- import random # 生成第一个随机数 print "random() : ", random.random(1,10) # 生成第二个随机数 print "random() : ", random.random(1,10)
The output result after running the above example is:
2 5
More Python related technical articles , please visit the Python Tutorial column to learn!
The above is the detailed content of How to import random in python. For more information, please follow other related articles on the PHP Chinese website!