趣學python第7章函式
函式的組成部分三個,函式名,引數,函式體
列印出hello,wangdef testfunc(name):
print('hello, %s' %name)
testfunc('wang')
***************==== restart: c:\python27\lianxi\2018123.py ***************====
hello, wang
姓加名def testfunc2(name,name1):
print('hello, %s %s' % (name,name1))
first = 'wang'
second = 'yan'
testfunc2(first,second)
hello, wang yan
兩個引數的呼叫。
函式體內變數的定義域,只在函式中存在,
在上面的**下加
testfunc2(name,name1)
traceback (most recent call last):
file "c:\python27\lianxi\2018123.py", line 8, in
testfunc2(name,name1)
nameerror: name 'name' is not defined
會報錯,name 未定義。
x3可以在函式定義中使用,但x1,在函式定義結束時不可以使用。x3= 6
def testfunc2(x1,x2):
x = x1 * x2 + x3
print (x)
testfunc2(2,8)
趣學python第7章使用模組
趣學python第7章使用模組 1.time模組 import time 引入時間模組 print time.time restart c python27 lianxi 2018123.py 1517052225.95 列印出一串數字 更改列印函式,print time.asctime sat j...
趣學python第7章練習題
7.4 1月球體重,基礎函式 編寫乙個函式,把初始體重和每年增加的體重作為引數 coding utf 8 2018 2 1 author linda def weight moon weight,x for x1 in xrange 1,16 weight weight x y weight mon...
趣學PYTHON第3章 字串
字串的使用,可以是英文單引號,雙引號,都可以輸出 1.但是當字串超過了一行,就要使用三個單引號了。否則會報錯。三個單引號可以解決這個問題,eol while scanning string literal 2.引號用來標註字串,但是如果輸出的字串也包含引號,怎麼辦。silly string he s...