通过编程方式,将字符串中的 数字及特殊符号 剔除, 保留 I like chinese
My_str =' 123 I like 456 chinese ? ^&* '
方法一:
str1=''
list1=My_str.split()
for x in list1:
if x.isalpha():
str1=str1+x+' '
print(str1)
方法二:
for i in My_str:
if 64<ord(i)<74 or 96<ord(i)<123 or ord(i)==32:
print(i,end='')
方法三:
My_str ="123 I like 456 chinese ? ^&* "
s=My_str.split()
for i in range(0,len(s)):
if s[i].isalpha()==False:
My_str=My_str.replace(s[i],'')
print(My_str)
方法四:
str1 = 'username=lisi&password=123456&address=中贸广场'
name = (str1.split('&')[0]).split('=')[0]
name1 = (str1.split('&')[0]).split('=')[1]
pswd = str1.split('&')[1].split('=')[0]
pswd1 = str1.split('&')[1].split('=')[1]
add = str1.split('&')[2].split('=')[0]
add1 = str1.split('&')[2].split('=')[1]
k1 = (name, name1, pswd, pswd1, add, add1)
k = dict(name=name1, pswd=pswd1, add=add1)
print(k)
方法五: