str1 = 'I Love LsgoGroup
print(str1[:6])# I Loveprint(str1[5])# eprint(str1[:6]+”插入的字符串" + str1[6:])# I Love插入的字符串 L sgoGroup
s ='Python'print(s)# Python print(s[2:4])# thprint(s[-5:-2])# ythprint(s[2])# tprint(s[-1])#n
内置函数
book ="book"
Book =book.capitalize()print(Book)
book2=Book.lower()print(book2)
book3 =book2.upper()print(book3)
book4 =book3.swapcase()print(book4)# Book# book# BOOK# book
>>> chars =" Make in China ">>> chars2 =chars.lstrip()>>> chars3 =chars.rstrip()>>> char5 =chars.strip()>>>print(chars2,'\n',chars3,'\n',char5)
Make in China
Make in China
Make in China
partition
>>> str5 ="I love China">>> str5 =" I love China ">>> str5.strip().partition("C")('I love ','C','hina')>>> str5.strip().rpartition("h")('I love C','h','ina')>>>str=" I love Beijing ">>>str.strip().replace("I","We")'We love Beijing'
split(str=’ ',num)
>>> string =" Changjiang River is the most beautiful scence in the world! ">>> string2 =string.strip().split()>>> string3 =string.strip().split("o")>>>print(string2,'\n',string3)['Changjiang','River','is','the','most','beautiful','scence','in','the','world!']['Changjiang River is the m','st beautiful scence in the w','rld!']
str3 ="""
say
hello
world
"""
str3.split('\n')# ['', ' say', 'hello', 'world ', '']