日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python输入字符串str_python字符串(str)

發(fā)布時間:2023/12/9 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python输入字符串str_python字符串(str) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

#value = "raitOrEi"#v = value.capitalize()#首字母大寫#print(v)#v1 = v.casefold()#全部變小寫,不只是英文的,其他語言特殊的大小寫也變換#print(v1)#v2 = v.lower()#只是英文變小寫#print(v2)

#設(shè)置寬度,并將內(nèi)容居中#20 代指總長度#只能填充一個字符,字符可有可無,沒有字符用空格填充#value = "raitorei"#v = value.center(20)#print(v)#v1 = value.center(20,"*")#print(v1)#v2 = value.ljust(20,"*")#print(v2)#v3 = value.rjust(20,"*")#print(v3)#v4 = value.zfill(20)#只能用0填充#print(v4)

#去字符串中尋找,尋找子序列的出現(xiàn)次數(shù)#value = "reraitorei"#v1 = value.count('re')#v2 = value.count('re',5)#v3 = value.count('re',5,6)#起止位置#print(v1)#print(v2)#print(v3)

#encode#decode

#以什么開始#以什么結(jié)尾#test = "raitorei"#v = test.startswith('r')#print(v)#v = test.endswith('i')#print(v)

#把字符串中的 tab 符號('\t')轉(zhuǎn)為空格,tab 符號('\t')默認的空格數(shù)是 8.#具體規(guī)則是,括號里是多少,以這個數(shù)字為一組,如果是開頭,空格占位數(shù)字多少。比如#test = "123\t456789"#v = test.expandtabs()#123 456789 8個一組,空格補缺少的位置#print(v)#v1 = test.expandtabs(6)#123 456789 6個一組,空格補缺少的位置#print(v1)

#從開始往后找,找到第一個之后,獲取位置#大于等于開始,小于結(jié)束,未找到 -1#test = "rei"#v = test.find('r',0,2 )#print(v)

#index找不到,報錯 忽略#test = "rei"#v = test.index('a')#print(v)

#將一個字符串中的占位符替換為指定的值#test = "I'm {name}, age {a}"#print(test)#v = test.format(name='raitorei',a=22)#print(v)

#將一個字符串中的占位符替換為指定的值,字典#test = "I'm {name}, age {a}"#print(test)#v = test.format_map({"name": 'raitorei', "a": 22})#print(v)

#星號 字符串中是否只包含字母,數(shù)字,漢字#test = "fdfd1f風動旛動3"#v = test.isalnum()#print(v)

#星號 判斷字符串中是否只包含字母,數(shù)字,漢字#test = "fdfdf風動旛動"#v = test.isalpha()#print(v)

#判斷字符串中是否是數(shù)字#test = "123②"#v = test.isdecimal()#②,特殊的不可以#v1 = test.isdigit()#二,中文的數(shù)字不支持#v2 = test.isnumeric()#print(v,v1,v2)

#數(shù)字 字母 下劃線 標識符:def class#test = "a123"#v = test.isidentifier()#數(shù)字開頭false#print(v)

#數(shù)字 字母 下劃線 標識符:def class#test = "a123"#v = test.isidentifier()#數(shù)字開頭false#print(v)

#是否存在不能打印的字符,比如\t,結(jié)果是false#test = "a\t123"#v = test.isprintable()#print(v)

#判斷是否全部是空格#test = " \t"#v = test.isspace()#print(v)

#判斷是否是標題#test = "the loneliest girl"#v = test.istitle()#print(v)#v1 = test.title()#print(v1)#v2 = v1.istitle()#print(v2)

#***** 加入字符#test = "_"#value = "raitorei"#v = test.join(value)#等于"".join(value)#print(v)

#islower() 方法檢測字符串是否由小寫字母組成。#isupper() 方法檢測字符串中所有的字母是否都為大寫。#test1 = "abc"#test2 = "abc123"#test3 = "abc123A"#v1 = test1.islower()#v2 = test2.islower()#v3 = test3.islower()#print(v1,v2,v3)#test4 = "ABC"#test5 = "ABC123"#test6 = "ABC123a"#v4 = test4.isupper()#v5 = test5.isupper()#v6 = test6.isupper()#print(v4,v5,v6)

#變換大小寫#test = "asdfgh"#v = test.upper()#print(v)#v = v.lower()#print(v)

#默認去除左右空格,\t,\n;可以指定字符#test = " a s fgh "#v = test.lstrip()#print(v)#v = test.rstrip()#print(v)#v = test.strip()#print(v)#v1 = v.strip("h")#print(v1)

#變換大小寫#test = "asdfgh"#v = test.maketrans("asd","123")#print(v)#v1 = test.translate(v)#print(v1)

#分割字符,partition包含分隔符,split不包含分隔符#test = "asdfghasdfghasdfgh"#v1 = test.partition("f")#print(v1)#v2 = test.rpartition("f")#print(v2)#v3 = test.split("f",2)#print(v3)#v4 = test.rsplit("f",2)#print(v4)

#分割換行符,默認不包含分隔符(false),true包含分隔符#test = "asdfg\nhasd\nfghasdfgh"#v1 = test.splitlines(True)#print(v1)

#分割換行符,默認不包含分隔符(false),true包含分隔符#test = "asdfg\nhasd\nfghasdfgh"#v1 = test.splitlines(True)#print(v1)

#大小寫轉(zhuǎn)換#test = "asdfghJKL"#v1 = test.swapcase()#print(v1)

#替換

test = "asdfghaJKaL"

#v1 = test.replace("a","b")#print(v1)#v2 = test.replace("a","b",2)#print(v2)################基本(7個)#################join#split#find#strip#upper#lower#replace################灰魔法(5個)################

test = "raitorei"

##索引#v1 = test[0]#print(v1)

##切片#v2 = test[0:-1]#print(v2)

##長度#v3 = len(test)#print(v3)#li = [1,2,3,4,5,"123"]#print(len(li))

#循環(huán)輸出#index = 0#while index < len(test) :#print(test[index])#index += 1#print("---end---")

#for demo in test:#print(a)

#幫助創(chuàng)建數(shù)字,可以設(shè)置隔多少再創(chuàng)建#v = range(0,100,5)#print(v)#for vv in v:#print(vv)#將輸入的文字的索引輸出

value = input(">>>")

length=len(value)

num=range(0,length)for f innum:print(f,value[f])#*****注意:

#字符串一且自,不可修改。

#一且修改或者拼接,部會造成重新生成字符串

總結(jié)

以上是生活随笔為你收集整理的python输入字符串str_python字符串(str)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。