def?calc(average):
公司主營(yíng)業(yè)務(wù):網(wǎng)站設(shè)計(jì)制作、網(wǎng)站設(shè)計(jì)、移動(dòng)網(wǎng)站開(kāi)發(fā)等業(yè)務(wù)。幫助企業(yè)客戶(hù)真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競(jìng)爭(zhēng)能力。創(chuàng)新互聯(lián)建站是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開(kāi)放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對(duì)我們的高要求,感謝他們從不同領(lǐng)域給我們帶來(lái)的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶(hù)帶來(lái)驚喜。創(chuàng)新互聯(lián)建站推出措勤免費(fèi)做網(wǎng)站回饋大家。
sum=0
for?i?in?average:
sum+=i
return?(sum/3)
print(calc([1,2,3]))
代碼解釋如下:
input_file作為變量,指的是一個(gè)文件的路徑;
current_file = open(input_file)這一句獲取input_file的內(nèi)容,這時(shí)候current_file 相當(dāng)于f;
print_all (current_file)就是用current_file調(diào)用了print_all 函數(shù),此時(shí)f=current_file;
此時(shí),解決了提問(wèn)者的第一個(gè)疑問(wèn)。
def是定義函數(shù)的一個(gè)聲明語(yǔ)句,語(yǔ)法結(jié)構(gòu)如下:
def?FunctionName(para1,para2):
print?"創(chuàng)建示例"
所以:
def?print_all(f):
print?f.read()定義了一個(gè)print_all的函數(shù),該函數(shù)有一個(gè)變量稱(chēng)作f;
print f.read()是這個(gè)函數(shù)的執(zhí)行語(yǔ)句;
簡(jiǎn)單來(lái)說(shuō)
str()將數(shù)值轉(zhuǎn)成字符串
repr()將對(duì)象轉(zhuǎn)成字符串顯示,注意只是顯示,有些對(duì)象轉(zhuǎn)成字符串沒(méi)有意義。如list,dict使用str()是無(wú)效的,但使用repr可以,這是為了顯示他們的值
以下內(nèi)容摘自google
The str() function is meant to return representations of values which are fairly
human-readable, while repr() is meant to generate representations which can be read by the interpreter (or will force a SyntaxError if there is not equivalent syntax). For
objects which don't have a particular representation for human consumption, str() will
return the same value as repr(). Many values, such as numbers or structures like lists
and dictionaries, have the same representation using either function. Strings and
floating point numbers, in particular, have two distinct representations.
Some examples:
s = 'Hello, world.'
str(s)
'Hello, world.'
repr(s)
"'Hello, world.'"
str(0.1)
'0.1'
repr(0.1)
'0.10000000000000001'
x = 10 * 3.25
y = 200 * 200
s = 'The value of x is ' + repr(x) + ', and y is ' + repr(y) + '...'
print s
The value of x is 32.5, and y is 40000...
# The repr() of a string adds string quotes and backslashes:
hello = 'hello, world\n'
hellos = repr(hello)
print hellos
'hello, world\n'
# The argument to repr() may be any Python object:
repr((x, y, ('spam', 'eggs')))
"(32.5, 40000, ('spam', 'eggs'))"
# reverse quotes are convenient in interactive sessions:
`x, y, ('spam', 'eggs')`
"(32.5, 40000, ('spam', 'eggs'))"
網(wǎng)站名稱(chēng):python菜鳥(niǎo)函數(shù),Python函數(shù)
本文URL:http://aaarwkj.com/article16/dssjpgg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開(kāi)發(fā)、用戶(hù)體驗(yàn)、網(wǎng)站導(dǎo)航、面包屑導(dǎo)航、網(wǎng)站維護(hù)、云服務(wù)器
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)