python的import与 from……import

在python用import或者from...import来导入相应的模块。

  • 将整个模块(somemodule)导入,格式为:importr somemodule
  • 从某个模块中导入某个函数格式为:from somemodule import somefunction
  • 从某个模块中导入多个函数,格式为:from somemodule import firstfunc,secondfunc,thirdfunc
  • 将某个模块中的全部函数导入,格式为:from somemodule import*

生成随机数

import random # 引入随机数库

x = random.randint(0,3) # 随机生成[0,3]之间的一个数,赋值给x

print(x)
如果真的不知道做什么 那就做好眼前的事情吧 你所希望的事情都会慢慢实现...
原文地址:https://www.cnblogs.com/sunbr/p/13635790.html