Python基礎一

來源:互聯網
上載者:User

標籤:16px   end   字元   font   運算   資料類型   www.   title   格式   

這是12月規劃的內容,2018年一月開篇~

如果有什麼錯誤,還請提出來~

前篇內容

http://www.cnblogs.com/yinghualuowu/p/7742663.html

print用法

無論什麼類型都可以直接輸出(資料類型會在下篇說)

比如

1 x=12 print(x)3 s="hello world"4 print(s)5 list_a=[1,2,‘a‘,[1,2]]6 print(list_a)7 dict_a={‘a‘:1,‘b‘:2}8 print(dict_a)
1hello world[1, 2, ‘a‘, [1, 2]]{‘a‘: 1, ‘b‘: 2}

 

格式化輸出

類似於printf,有%d,%s啥的
比如
1 s="hello"2 a=20183 print("%s %d" %(s,a))
hello 2018
1 PI=3.14159262 print("%f"%PI)3 print("%.3f"%PI)4 num=1234567895 print(num)6 print("%10.3f"%PI)#欄位寬10,精度3  num用於對比7 print("%-10.3f"%PI)8 print("%010.3f"%PI)#用0填充空白
3.1415933.142123456789     3.1423.142     000003.142

 

print預設換行

哦,不想換行...

1  print (x,end = ‘‘)  

 

各種很懶的操作

字串的有些操作

1 x="hello"2 y="world"3 print(x+y)#拼接4 print(x*2)5 print("12"+"34")6 print("12"*2)
helloworldhellohello12341212

四則運算也是可以的

 到這裡就差不多了

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.