python學習筆記

來源:互聯網
上載者:User

標籤:python筆記

t=“i am {},age {} ,{}”、format("seven",18,"wang")

必須一一對應否則報錯

穿字典需加**

t = “i am {name},age {age} ,really{name}”、format(**{"name":"seven","age":18})

print(t)

結果:i am seven,age 18,reallyseven

傳列表

t=“i am {:s},age{:d}”、format(*["seven",18])

已二進位,八進位,整型,十六進位,十六進位大寫,按百分比顯示(預設顯示小數點後六位)

tp1="number:{:b},{:o},{:d},{:x},{:X},{:%}"、format(15,15,15,15,15.87623,2)

結果:number:1111,17,15,f,F,1587.621450%

函數:

python中函數的定義:函數是邏輯結構化和過程化的一種編程方式。

def test(x):#x為形參,def關鍵字 test為函數名

第二行寫注釋

後面寫N行代碼

return x #返回一個結果

使用函數的好處:

1.代碼重用

2.保持一致性,以維護

3.可擴充

過程:可理解為沒有傳回值的函數。

若傳回值為0,即沒有return 則返回None

傳回值為1:返回object

傳回值>1,返回tuple                       圓柱模板

函數的參數:def calc(x,y):

                            res=x**y

                              return res 

                                c=calc(a,b)

第一行x,y為形參,只有在被調用時才分配記憶體單元,在調用結束是,立即釋放所分配的記憶體單元。


python學習筆記

聯繫我們

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