python筆記一

來源:互聯網
上載者:User

標籤:標準輸出   tabs   you   對象   win   有序   位置   學習   abs   

字串學習---------- input互動輸入----------
name = input( ‘please enter your name:‘ )print (name)
---------- input 互動輸入計算----------
value1 = 1024 * 512value2 = input(‘num1:‘)value3 = input(‘num2:‘)print (value1)print (value2)print (value3)print (value1 * value2)print (value1 * value3)#當value2 * value3的時候不能如上表示
---------- in 判斷變數/值中包含的字串----------
s = "Wind and cloud"weather1 = "Wind" in sweather2 = "SB" in sprint (weather1)print (weather2)
---------- 變數元組 ----------
Wind = "weather1"Paul = "name"Rain = "weather2"_Coll_1 = [‘Wind‘,‘Paul‘,‘Rain‘]print(_Coll_1)_Cont_1 = "Wind" in _Coll_1print (_Cont_1)
---------- type 查看對象的類,一般字串都是標準輸入----------
temp1 = "123"_123_io = type(temp1)print(_123_io)temp2 = "hey"_hey_io = type(temp2)print(_hey_io)
---------- dir 查看功能----------
temp = "wind"print(dir(temp))
---------- upper 小寫轉換成大寫----------
temp = "wind"print(temp.upper())
---------- count 字串統計一定要在一對引號之內的字串----------
_name_coll = ("paul,vencent,sunny,anny,should,bilibili,david,paul")_coll = _name_coll.count("nn")print(_coll)
---------- endswith 字串尾部輸出定義----------
temp = "hello"print(temp.endswith(‘e‘,0,2))    #字串的0-2的字元he,是以e結尾,0也可以寫成1
---------- center 佔位輸出----------
a1 = "alex"a2 = a1.center(20,‘*‘)print(a2)#字元總數20個,以alex為中心,兩邊以*號填充
---------- count 統計指定字串數量----------
a1 = "alex is alpa"a2 = a1.count(‘al‘,5,12)print(a2)
---------- expandtabs 分隔字元設計20位----------
content = "hello\t123"print(content)print(content.expandtabs())print(content.expandtabs(20))
---------- find 字串位元尋找
s = "alex hello"print(s.find("h"))print(s.find("p"))#找不到的字元,會顯示負數
---------- str 字串標準輸出,字串位置輸出定義
str = ‘Runoob‘print  (str[0:3])print (str[0])print (str[2:5])print (str[2:])print (str * 2)print (str + "TEST")
---------- \n 本身是分行符號,r將字串中特殊字元轉化為一般字元
print(‘Ru\nnoob‘)print(r‘Ru\nnoob‘)
---------- format 佔位替換,有序排列
x = "hello {0}, age {1}"print(x)y = x.format("paul","27")print(y)
---------- join
alex = "name1"should = "name2"paul = "name3"dio = "name5"name = [alex ,should ,paul ,dio]_name_join = "".join(name)print(_name_join)#將值變成一個整體字串輸出,如果不用元組,只是字串,可以使用雙引號把字串引起來,加入空格,是字串相互隔開。name = "alex ","should ","paul ","dio "print (name)_name_join = "".join(name)print(_name_join)
---------- replace 替換字串
x = "alex is alex"y = x.replace("al","AA")print(y)
---------- split 對字串進行切片分隔
x = "alex\nalex"y = x.split()print(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.