python第三天

來源:互聯網
上載者:User

標籤:列表   isl   sla   git   nta   tty   轉換   python   tran   

#字串的用法

#Author:ge jian
name = ‘My name is {name} and I am {year} old‘

print(name.capitalize())#首字母大寫
print(name.count(‘a‘))#字元個數
print(name.center(50,‘-‘))#不足補齊
print(name.endswith(‘n‘))#判斷以什麼字元結尾
print(name.expandtabs(tabsize=20))#\t tab建轉空格
print(name[name.find(‘is‘):10])
print(name.format(name=‘alex‘,year=20))
print(name.format_map({‘name‘:‘alex‘,‘year‘:‘30‘}))
print(‘ab12‘.isalnum())#包含數字和字母
print(‘As‘.isalpha())#包含純字母
print(‘11A‘.isdecimal())
print(‘2314‘.isdigit())#是否是整數
print(‘add‘.isidentifier())#判斷是否是一個合法的標識符
print(‘dAasda‘.islower())#是否都是小寫
print(‘0001‘.isnumeric())#是否只包含數字
print(‘ ‘.isspace())#是否是空格
print(‘My Name Dss‘.istitle())
print(‘dsafd‘.isprintable())#tty file,drive file
print(‘ASD‘.isupper())#是否大寫
print(‘+‘.join([‘1‘,‘2‘]))#後面字串按照前面的格式拼接
print(name.ljust(50,‘*‘))#不夠長度後面用*補上
print(name.rjust(50,‘+‘))#不夠長度前面用*補上
print(name.lower())#大寫變小寫
print(name.upper())#小寫變大寫
print(‘\nAlex\n‘.lstrip())#去掉左邊的空格和斷行符號
print(‘\nAlex\n‘.rstrip())#去掉右邊的空格和斷行符號
print(‘\nAlex\n‘.strip())#去掉兩邊的空格和斷行符號
p = str.maketrans(‘abcdefd‘,‘123434556‘)
print(‘alex li‘.translate(p))

print(‘alex li‘.replace(‘l‘,‘A‘,1))#把前面的替換成後面的
print(‘alex li l‘.rfind(‘l‘))#找到最右邊的對應的下標
print(‘alex li‘.split(‘l‘))#把字串按照‘‘變成列表
print(‘1+2\n+3+4‘.splitlines())#
print(‘Alex Fu‘.swapcase())#除首字母之外大小寫轉換
print(‘Alex li‘.title())
print(‘Alex.li‘.zfill(20))





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.