
def send_to_twitter(msg):
password_manager = urllib.request.HTTPPasswordMgr()
password_manager.add_password("Twitter API",
"http://twitter.com/st
http_handler = urllib.request.HTTPBasicAuthHandler(pas
page_opener = urllib.request.build_opener(http_handle
urllib.request.install_opener(page_opener)
params = urllib.parse.urlencode( {'status': msg} )
resp = urllib.request.urlopen("http://twitter.com/sta
resp.read()
參數探究
要在 Python 裡使 用 參 數 , 只 須 在 函 式 名 稱 定 義 之 後 與 冒 號 之 前 的 圓
括 號 裡 插 入 變 數 名 稱 , 然 後 在 函 式 本 身 之 內 , 按 照 尋 常 方 式 使 用 該 變 數
即可︰
def shout_out(the_name):
return("Congratulations " + the_name + "!")
之 後 , 每 當 使 用 函 式 時 ,