python format字串格式化、數學意義的函數與python中的函數 day14

來源:互聯網
上載者:User

標籤:return   程式   python   ram   eve   邏輯   orm   ini   nbsp   

format字串格式化,必須一一對應

tpl = ‘i am {}, age{},{}‘.format(‘seven‘,18,12)print(tpl)
tpl = ‘i am {1}, age{2},{2}‘.format(‘seven‘,18,12)print(tpl)

取元組第一個

tpl = ‘i am {0[0]}’,format([1,2,3],[123])

 

python 中函數定義方法:

def test(x):    ‘The function definitions‘#注釋函數    x+=1    return x

 

def:定義函數的關鍵字

test:函數名

():內科定義形參

‘’文檔描述,非必要,強烈建議添加

x+=1:泛指代碼塊或程式處理邏輯

return:定義傳回值

使用函數

def test(x):    ‘:param X:整形數字‘#注釋函數    y=2*x+1    return yprint(test)a = test(3)print(a)

沒有傳回值,返回None

只有一個傳回值,返回該值

有多個傳回值,返回元組

 

函數的參數

形參,只有調用函數時才有用

實參,一直存在

形參,實參一一對應

def text(x,y):    res=x*y    return resz = text(1,2)print(z)

參數組  **字典 *列表

def text(x,*y):    print(x)    print(y)c= text(1,2,3,4,5)

 

python format字串格式化、數學意義的函數與python中的函數 day14

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.