day3-python學習筆記(四)

來源:互聯網
上載者:User

標籤:文字   字串方法   數組   python   ali   file   字串格式化   span   一個   

字串方法

#字串這些方法都不會改變原來字串的值
name = ‘beSTtest‘
# new_name = name.strip()#預設是去掉空格和分行符號
# new_name = name.lstrip()#預設是去掉左邊的空格和分行符號
# new_name = name.rstrip()#預設是去掉右邊的空格和分行符號
# new_name = name.count(‘t‘)#尋找某個字元在字串裡面出現的次數
# index = name.find(‘t‘)#找到這個字串,返回它的下標,如果不存在的話,返回-1
# index = name.index(‘d‘)#找到這個字串,返回它的下標,如果不存在的話,報錯
# print(name.upper())#把所有字母都變成大寫的
# print(name.lower())#把所有字母都變成小寫
# file_name = ‘a.xls‘
# print(file_name.endswith(‘.xls‘))#判斷一個字串是否以xx結尾
# sql = ‘select,update,insert,drop,create,alter‘
sql = ‘select * from user;select‘
sql.startswith(‘select‘)#判斷一個字串是否以xx開頭
# f = ‘{name} 歡迎光臨 age :{age}‘
# # print(f.format(name=‘青‘))#字串格式化
# d = {‘name‘:‘flynn‘,‘age‘:18}
# print(f.format_map(d))#字串格式化,它傳進去的是一個字典
new_sql = sql.replace(‘select‘,‘update‘)
# print(new_sql)
# print(‘123‘.isdigit())#是否是數字
# print(‘&‘.isalnum())#是否包含數字或字母

# st = ‘a,b,c,d,f,g‘
# st_list = st.split(‘,‘)#字串分割,返回的是list,如果什麼都不寫,是按照空格分割
# print(st_list)

slit = [‘a‘,‘b‘,‘c‘,‘d‘,‘f‘,‘g‘]
s2 =‘hhhhhhh‘
tu = (‘h1‘,‘h2‘,‘h3‘,‘h5‘)
d ={‘name‘ :‘n‘,‘age‘:18}
res = ‘*‘.join(d)#數組連起來,返回字串

print(res)



#可遺忘的
# new_name = name.capitalize() 首字母大寫
# print(name.center(50,‘*‘))把字串放中間,兩邊用*補齊
# print(‘aaAA‘.islower())#是否全是小寫字母
# print(‘AA‘.isupper())#是否全是大寫字母
# print(‘sdsad‘.isalpha())#是否包含英文字母

day3-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.