Python 初體驗(六)

2022-08-04 20:15:18 字數 638 閱讀 6318

import random,發現這裡面有很多randomize的method,這裡不再一一贅述,可以通過幫助文件自習看,包括choice,shuffle都是整合度很高的randomize方法

於是嘗試了乙個這樣乙個task,輸入字串長度,輸出乙個隨機產生的字串。鞏固了一下異常的相關處理方法。

''.join(temp)

#input length

while true:

try:

length = input('input length: ')

if type(length) == int and length > 0:

break

else:

print 'no kidding, seriously!'

except nameerror:

print 'no kidding, seriously!'

except syntaxerror:

print 'no kidding, seriously!'

print getstr(length)

利用py2exe可以生成可執行檔案。步驟如下:

編寫好執行指令碼,如:上述這段**。命名為 exercise.py

編寫編譯指令碼compile.py

python 執行緒初體驗

import threading import time class mythread threading.thread def init self,threadid,name,counter threading.thread.init self self.threadid threadid sel...

python函式初體驗

形式引數 被指定具體的值 預設引數,實際引數是呼叫時候的實際指定引數 我們把函式 的引數叫形式函式,函式實際調 的時候,賦予的引數叫實際函式 定義函式的時候,指定形式引數具體的值,這樣的引數叫預設引數 動態引數 動態引數可以解決形式引數 個數 型別 不確定的時候,在動態引數裡,代表元組,代表字典。當...

Python爬蟲之初體驗

python爬蟲,一般用於抓取特定的內容,最近想學學,通過網路抓取自己想要的內容,於是乎學習了一下python,用乙個小案例來紀念一下學習的成果。coding utf 8 import urllib import re 定義個函式 抓取網頁內容 def gethtml url webpage url...