Python 變數 資料類型-字串 二

來源:互聯網
上載者:User

標籤:ima   它的   總結   html   print   blog   ref   不能   技術分享   

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

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

Python print函數 一

Python 中的變數賦值不需要型別宣告,好了知道這個就可以了

我們還可以看一看類型

1 num=1.2332 str="1.233"3 print(type(num))4 print(type(str))
<class ‘float‘><class ‘str‘>

 

資料類型-字串

單引號,雙引號用法相同

1 str="1.233"2 string=‘1.233‘3 print(str)4 print(string)
1.2331.233

三引號表示多行的字串

1 str=‘‘‘asdasd2 asdasdasd3 asdasdasd4 adas‘‘‘5 print(str)
asdasdasdasdasdasdasdasdadas

還有各種的轉義...我覺得記一點常用的就行了,其他用的時候再查一查

逸出字元 描述
\(在行尾時) 續行符
\\ 反斜線符號
\‘ 單引號
\" 雙引號

還有它的運算子

+,*都表示過了,我們看一看[ ],in,not in

1 str="helloworld"2 print(str[1])3 print(str[1:4])#區間是左閉右開,注意負數是從右至左4 print(str[:5])5 print(str[4:])
eellhellooworld
1 str="helloworld"2 print("h"in str)3 print("h" not in str)
TrueFalse

r或者R,原始字串 - 原始字串:所有的字串都是直接按照字面的意思來使用,沒有轉義特殊或不能列印的字元。轉義記不住的可以用這個

1 str=r"D:\eclipse\readme"2 print(str)
D:\eclipse\readme

最後它的內建函式,自己一個個玩吧~以後會有個總結。

 

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.