字符串

1.#split(str=" ", num )

#以str为分隔符截取字符串,指定num,仅截取num个字符串

str38 =" sunck ** is***********a****good*man"

liststr38.split("*")

print(str38.split("*"))

2. 查找字符串中单词的个数

  print(list39)

  c=0

  for s in list39:

        if len(s)>0:

        c +=1

print(c)

3.以换行符分割字符串

 #splitlines([keepends])  以(' ', ' ', ' ')为分隔符截取字符串返回

 str40= ' ' ' sunck is a good man!

  sunck is a nice man!

  sunk is handsome man !

'''

print(str40.splitlines())

4.#join(seq) 以指定的字符串分隔符,将seq中的所有元素组合成一个字符串

list41 = ['sunck' , 'is' , 'a', 'good', 'man']

str42="&".join(list41)

print(str42)

5字符串求最大最小值

  .#max() min()

str43 = "sunck is a good man!z"

print(max(str43))

print("*"+min(str43)+"*")

6.字符串替换

str44 = "sunck is a good good good man"

str45 = str44.replace("good","nice")

print(str45)

原文地址:https://www.cnblogs.com/weichenji0/p/8616354.html