python控制流程-匯入模組

來源:互聯網
上載者:User

標籤:語句   page   1.0   font   rand   關鍵字   調用   含義   文法   

一、模組

1.含義Python 程式可以調用一組基本的函數,這稱為“內建函數”,包括你見到過的 print()、input()和 len()函數。Python 也包括一組模組,稱為“標準庫”。每個模組都 是一個 Python 程式,包含一組相關的函數,可以嵌入你的程式之中。 2.文法形式在開始使用一個模組中的函數之前,必須用 import 語句匯入該模組。在代碼中, import 語句包含以下部分:
(1)import 關鍵字
(2)模組的名稱
(3)可選的更多模組名稱,之間用逗號隔開

3.例

#!/usr/bin/env python
#coding:utf-8
import random
for i in range(5):
    print(random.randint(10,100))

匯入random模組,產生5個 10-100間的隨機整數

二、匯入模組方式

1.使用import 匯入模組,在語句中使用 模組.函數 的形式

(1)調用單個模組

#!/usr/bin/env python
#coding:utf-8
import random
for i in range(5):
    print(random.randint(10,100))

(2)同時調用多個模組

import sys, os, random

2.使用 “from 模組 import *”

#!/usr/bin/env python
#coding:utf-8
from random import *
for i in range(5):
    print(randint(10,100))

 

python控制流程-匯入模組

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.