0%
Theme NexT works best with JavaScript enabled
你那能叫活着么?你那只能叫没死。
### 去空格
1 2 3 4 5 6 s = ' yang guo qi ' s= s.strip() print (s)
### 去一些特殊符号
1 2 3 s = ' yang guo qi , ' s= s.strip().strip(',' ) print (s)
### 计算长度
1 2 3 s = ' yang guo qi , ' s= len (s) print (s)
### 大小写转换
1 2 3 4 5 6 7 s = ' yang guo qi , ' s= s.upper() print (s)s = ' Yang guo qi , ' s= s.lower() print (s)
### 反转字符串
1 2 3 s = ' Yang guo qi , ' s= s[::-1 ] print (s)
### 查找字符串
1 2 3 4 s = ' Yang guo qi , ' d = 'qi' print (s.find(d))
### 字符串截取
1 2 3 4 5 6 7 8 9 10 11 str = ’0123456789′print (str [0 :3 ]) print (str [:]) print (str [6 :]) print (str [:-3 ]) print (str [2 ]) print (str [-1 ]) print (str [::-1 ]) print (str [-3 :-1 ]) print (str [-3 :]) print (str [:-5 :-3 ])
### 分割字符串
1 2 3 4 5 6 7 8 s = 'Yang,guo qi' d = s.split(',' ) print (d)sStr1 = 'ab,cde,fgh,ijk' sStr2 = ',' sStr1 = sStr1[sStr1.find(sStr2) + 1 :] print (sStr1)
### 格式化
1 2 3 4 5 6 7 8 9 10 1. s = 'this is my {}' .format ('dog' ) print (s)2. s = 'this is my {} and {}' .format ('dog' ,'cat' ) print (s)3. 语法求解释urls = ['oa{}-New_York' .format (str (i)) for i in range (30 ,930 ,30 )] print (urls)