Python-字符串

Posted on 2020-05-24 14:19  RorinL  阅读(153)  评论(0编辑  收藏  举报

String基本方法

test = " helloWord "

1单词全部大写stringObj.upper();

print("testtextUpper=(" + test.upper() + ")")

2单词全部小写stringObj.lower();

print("testTextLower=(" + test.lower() + ")")

3单词首字母大写stringObj.title();

print("testTexttitle=(" + test.title() + ")\n")

4.去除空格stringObj.strip(),

print("testTexttitle=(" + test.title().strip() + ")")

4-1去左空格stringObj.lstrip();

print("testTextLower=(" + test.lower().lstrip() + ")")

4-2去右空格stringObj.rstript();

print("testtextUpperRstrip=(" + test.upper().rstrip() + ")")

 

二,str()方法与string,int互转

a='p'

print (type (a))  >>>(class 'str')
b=6

print(type (b))  >>>(class 'int')


#string转int

a2=int(a)

print (type (a2))  >>>(class 'int')
#int转string

b2=int(b)

print (type (b2))  >>>(class 'str')

 

我的个人网站https://www.rfbynet.club