python2019. 12. 26. 22:21
 



test_string = "Dave David"
#Return the number of non-overlapping occurrences of substring sub in
test_string.count('Id')

#결과
0

test_string = "Dave David"
test_string.index('D')
test_string.rindex('D')

#결과
5

#index, find 차이
test_string = "Dave David"
#문자가 존재하지 않는 경우 에러 발생
#test_string.index('f')
#문자가 존재하지 않는 경우 -1 return
print(test_string.find('f'))

#결과
-1

test_string = "Dave David"
#Concatenate any number of strings.
comma = ','
comma.join(test_string)

#결과
'D,a,v,e, ,D,a,v,i,d'

test_string = "   111Dave111 "

print(test_string.strip())
print(test_string.lstrip())
print(test_string.rstrip())
print(test_string.strip(' 1'))

#결과
111Dave111
111Dave111 
   111Dave111
Dave

test_string = "Dave David"

print(test_string.lower())
print(test_string.upper())

#결과
dave david
DAVE DAVID


test_string1 = "Dave David Dope"
test_string2 = "Dave/David/Dope"
print(test_string1.split())
print(test_string2.split('/'))
['Dave', 'David', 'Dope']
['Dave', 'David', 'Dope']


test_string = "(Dave)"
test_string.replace('(','[').replace(')',']')

#결과
'[Dave]'

Posted by easy16