最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python字符串string的內(nèi)置方法實例詳解

 更新時間:2018年05月14日 09:23:21   作者:PizerWang  
這篇文章主要介紹了python字符串string的內(nèi)置方法,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友參考下吧

下面給大家分享python 字符串string的內(nèi)置方法,具體內(nèi)容詳情如下所示:

#__author: "Pizer Wang"
#__date: 2018/1/28
a = "Let's go"
print(a)
print("-------------------")
a = 'Let\'s go'
print(a)
print("-------------------")
print("hello" * 3)
print("helloworld"[2:])
print("-------------------")
print("ell" in "helloworld")
print("-------------------")
print("Pizer is a good student")
print("%s is a goog student" % "Pizer")
print("-------------------")
a = "1234"
b = "abcd"
c = "!@#$"
d = a + b + c
print(d)
d = "".join([a, b, c])
print(d)
d = ", ".join([a, b, c])
print(d)
d = "++".join([a, b, c])
print(d)
print("-------------------")
print("string的內(nèi)置方法")
str = "helloworld"
print(str.count("l"))   #統(tǒng)計元個數(shù)
print(str.capitalize())   #首字母大寫
print(str.center(25, "-"))  #居中
print(str.endswith("d"))
print(str.endswith("world"))
print(str.endswith("word"))  #是否以某個內(nèi)容結(jié)尾
print(str.startswith("hello")) #是否以某個內(nèi)容開始
str = "hello\tworld"
print(str.expandtabs(tabsize=10))
print("-------------------")
str = "helloworld {name} is {age}"
print(str.find("w"))   #查找到第一個元素并將索引值返回
print(str.format(name = "Pizer", age = 18))
print(str.format_map({"name":"Jone", "age":25}))
print("-------------------")
print(str.index("w"))
#print(str.index("www"))  #報錯
print(str.find("wwww"))
print("-------------------")
str = "123abc"
print(str.isalnum())
str = "123"
print(str.isalnum())
str = "abc"
print(str.isalnum())
str = "!@$"
print(str.isalnum())
str = "中國萬歲"
print(str.isalnum())
print("-------------------")
print("123456".isdecimal())
print("123456ff".isdecimal())
print("123456789".isdigit())
print("12345.6789".isdigit())
print("12345.6789".isnumeric())
print("-------------------")
print("34abc".isidentifier())
print("_34abc".isidentifier())
print("abc".islower())
print("abC".islower())
print("ABC".isupper())
print(" ".isspace())
print("-------------------")
print("Hello Jone".istitle())
print("Good morning".istitle())
print("-------------------")
print("Hello Jone".lower())
print("Good morning".upper())
print("Hello Jone".swapcase())
print("-------------------")
print("Hello world".ljust(20, "-"))
print("Hello world".rjust(20, "-"))
print(" Hello world \t \n")
print(" Hello world ".strip())
print(" Hello world ".lstrip())
print(" Hello world ".rstrip())
print("-------------------")
print("Hello Jone Jone".replace("Jone", "Pizer"))
print("Hello Jone Jone".replace("Jone", "Pizer", 1))
print("My title".find("t"))
print("My title".rfind("t"))
print("-------------------")
print("Hello world".split(" "))
print("Hello world".split("l", 1))
print("Hello world".rsplit("l", 1))
print("hello jone".title())
print("-------------------")
#重要的字符串方法
# print(st.count('l'))
# print(st.center(50,'#')) # 居中
# print(st.startswith('he')) # 判斷是否以某個內(nèi)容開頭
# print(st.find('t'))
# print(st.format(name='alex',age=37)) # 格式化輸出的另一種方式 待定:?:{}
# print('My tLtle'.lower())
# print('My tLtle'.upper())
# print('\tMy tLtle\n'.strip())
# print('My title title'.replace('itle','lesson',1))
# print('My title title'.split('i',1))

執(zhí)行結(jié)果:

Let's go
Let's go
hellohellohello
lloworld
True
Pizer is a good student
Pizer is a goog student
1234abcd!@#1234abcd!@#
1234abcd!@#
 1234, abcd, !@#$
1234++abcd++!@#$
string的內(nèi)置方法
3
 Helloworld
——–helloworld——-
True
 True
 False
 True
hello world
5
 helloworld Pizer is 18
helloworld Jone is 25
5
-1
True
 True
 True
 False
True
True
 False
 True
 False
False
False
 True
 True
 False
 True
True
True
False
hello jone
 GOOD MORNING
hELLO jONE
Hello world———
 ———Hello world
 Hello world
Hello world
 Hello world
 Hello world
Hello Pizer Pizer
 Hello Pizer Jone
 3
5
[‘Hello', ‘world']
 [‘He', ‘lo world']
 [‘Hello wor', ‘d']
Hello Jone

總結(jié)

以上所述是小編給大家介紹的python字符串string的內(nèi)置方法實例詳解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Windows和Linux下Python輸出彩色文字的方法教程

    Windows和Linux下Python輸出彩色文字的方法教程

    這篇文章主要介紹了在Windows和Linux中Python輸出彩色文字的方法,通過設(shè)置彩色文字給大家更醒目的效果,文中給出了詳細的介紹和示例代碼,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-05-05
  • 機器學習python實戰(zhàn)之手寫數(shù)字識別

    機器學習python實戰(zhàn)之手寫數(shù)字識別

    這篇文章主要為大家詳細介紹了機器學習python實戰(zhàn)之手寫數(shù)字識別,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • 自學python用什么系統(tǒng)好

    自學python用什么系統(tǒng)好

    在本篇文章里小編給大家整理了一篇關(guān)于學python用什么系統(tǒng)好的相關(guān)文章,有興趣的朋友們可以學習下。
    2020-06-06
  • 在linux下實現(xiàn) python 監(jiān)控usb設(shè)備信號

    在linux下實現(xiàn) python 監(jiān)控usb設(shè)備信號

    今天小編就為大家分享一篇在linux下實現(xiàn) python 監(jiān)控usb設(shè)備信號,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-07-07
  • Python判斷for循環(huán)最后一次的6種方法

    Python判斷for循環(huán)最后一次的6種方法

    在Python中,通常我們不會直接判斷for循環(huán)是否正在執(zhí)行最后一次迭代,因為Python的for循環(huán)是基于可迭代對象的,它不知道也不關(guān)心迭代的內(nèi)部狀態(tài)(比如當前是第幾次迭代),但是,我們可以使用一些技巧來間接地實現(xiàn)這個需求,需要的朋友可以參考下
    2025-01-01
  • Pycharm配置lua編譯環(huán)境過程圖解

    Pycharm配置lua編譯環(huán)境過程圖解

    這篇文章主要介紹了Pycharm配置lua編譯環(huán)境過程圖解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-11-11
  • Python Pandas Dataframe.describe()使用及代碼實例

    Python Pandas Dataframe.describe()使用及代碼實例

    這篇文章主要介紹了Python Pandas Dataframe.describe()使用及代碼實例,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • Python 數(shù)據(jù)結(jié)構(gòu)之隊列的實現(xiàn)

    Python 數(shù)據(jù)結(jié)構(gòu)之隊列的實現(xiàn)

    這篇文章主要介紹了Python 數(shù)據(jù)結(jié)構(gòu)之隊列的實現(xiàn)的相關(guān)資料,需要的朋友可以參考下
    2017-01-01
  • arcgis使用Python腳本進行批量截圖功能實現(xiàn)

    arcgis使用Python腳本進行批量截圖功能實現(xiàn)

    最近公司數(shù)據(jù)部那邊有個需求,需要結(jié)合矢量數(shù)據(jù)和影像數(shù)據(jù),進行批量截圖,并且截圖中只能有一個圖斑,還要添加上相應的水印,這篇文章主要介紹了arcgis使用Python腳本進行批量截圖,需要的朋友可以參考下
    2023-01-01
  • Python如何使用ConfigParser讀取配置文件

    Python如何使用ConfigParser讀取配置文件

    這篇文章主要介紹了Python如何使用ConfigParser讀取配置文件,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-11-11

最新評論

宁都县| 望奎县| 尚义县| 墨江| 德安县| 南宫市| 永嘉县| 柳江县| 沙田区| 南澳县| 鹤岗市| 泰和县| 涪陵区| 巧家县| 宣威市| 达日县| 富顺县| 安乡县| 贵州省| 辽阳县| 祁门县| 台南市| 温州市| 武山县| 江阴市| 嫩江县| 海晏县| 聂荣县| 莒南县| 麻江县| 沙雅县| 略阳县| 松原市| 洱源县| 襄城县| 宽城| 扶绥县| 紫金县| 宁都县| 上蔡县| 普定县|