Home  >  Article  >  Backend Development  >  How to import random in python

How to import random in python

(*-*)浩
(*-*)浩Original
2019-07-19 16:02:0311083browse

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.

How to import random in python

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn