Python學習記錄-2016-12-20

來源:互聯網
上載者:User

標籤:字串操作

字串操作:

#!/usr/bin/env python# -*- coding: utf-8 -*-# Author:Jack Niuname = "My \tname is {name}"#加入一個tab鍵的空格print(name.capitalize())首字母大寫print(name.count("a"))#字串中有多少aprint(name.center(50, "-"))#長度50,位於中間,兩遍-補齊print(name.endswith("cke"))#是否以cke結尾print(name.expandtabs(tabsize=30))#30的tabsiziprint(name.find("is"))#尋找is的第一個字母的indexprint(name.format_map( {"name": "niubin"} ))#替換print("1A".isalnum())#是否是阿拉伯數字+阿拉伯字元print("sssAA".isalpha())#是否是英文字母print("10".isdecimal())#是否十進位print("10".isdigit())#是否是數字print("a10A".isidentifier())#判斷是不是一個合法的標識符,變數名print("a10a".islower())#是否是小寫print("3333".isnumeric())#是否是數字print(" ".isspace())#是否是空格print("My Name Is Jack".istitle())#是否是titleprint("My Name Is Jack".isprintable())#是否能列印,有些檔案不能列印print("MY NAME IS JACK".isupper())#是否大寫print(",".join(["1", "2", "3" ]))##1,2,3中間加入逗號print("my name is jack".ljust(50, "*"))#長度50,左邊*補齊print("my name is jack".rjust(50, "-"))#長度50,右邊-補齊print("My name is jack".lower())#把大寫變成小寫print("My name is jack".upper())#把小寫變成大寫print("My name is jack".replace("My", "MY", 1))#把小寫變成大寫,替換print(" Alex".lstrip())#去掉左邊的空格和斷行符號print("Alex ".rstrip())#去掉右邊的空格和斷行符號print(" Alex ".strip())#去掉左邊和右邊的空格和斷行符號p = str.maketrans("abcdef", "123456")print("Alex li".translate(p))#將alex li替換為123456中的對應字元print("1+2+3".split("+"))#以加號切片print("1+2\n+3+4".splitlines())#以分行符號切片print("AlexLi".swapcase())#全部轉換為大小寫反向print("My name is jack".rfind("name"))#print("my name is jack".zfill(50))#在前邊補0


Python學習記錄-2016-12-20

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.