pythonの文字列の一般的な組み込み関数の使用方法

1247 ワード

# -*- coding: utf-8 -*- 
#-------------------------------------------------------------------------------
# @Name:         str
# @Description:            
# @Author:       springbocai
# @Date:         2019/5/20
#-------------------------------------------------------------------------------
#          upper() lower()
str_1 ='springbocai'
str_2 ='SpringBOai'
s1 = str_1.upper() #    
s2 = str_2.lower() #    
print('      {}'.format(s1))
print('      {}'.format(s2))
#     find()
f1 = str_1.find('o')
print('      {}'.format(f1)) #                  ,     -1,                       

#     replace()
r1 = str_1.replace('g','love') #g   love
r2 = str_1.replace('g','love',2) #2      ,                str_1  1 g,      2 g
print('      {}'.format(r1))
print('      {}'.format(r2))

#       split()
sp = str_1.split('o') #       list,         str
print('      {}'.format(sp))

#        strip()
str_3 = '@@springbocai@@'
str_4 = '  springbocai  '
st = str_3.strip('@')
st2 = str_4.strip(' ')#        
print('       {}'.format(st))
print('       {}'.format(st2))