Python/Python__works

introducing python - strings

말하는감자 2019. 5. 31. 16:41
#--------------------------
f = 'apple \nbanana \npear'
print(f)
>> apple
>> banana
>> pear


#--------------------------
test = "\"apple\" love"
print(test)
>> "apple" love


#--------------------------
test = "\\apple\\"
print(test)
>> \apple\


#--------------------------
test = 'iloveapples'
print(test[0])
>> i
print(test[-1])
>> s
print(test[0:11:2])
>> ioepls
print(test[0:11:3])
>> ivpe


#--------------------------
test = 'i,hate,apple'
print(test.split(','))
>> ['i', 'have', 'apple']


#--------------------------
test = ['i', 'hate', 'apple']
print(', '.join(test))
>> i, hate, apple


#--------------------------
test = 'all apple hate'
print(test.startswith('all'))
>> True

print(test.endswith('apple'))
>> False


#--------------------------
test = 'i really!! hate apple'
print(test.strip('!')
>> i really hate apple

print(test.capitalize())
>> I really! hate apple

print(test.title())
>> I Really Hate Apple

print(test.upper())
>> I REALLY! HATE Apple

print(test.lower())
>> i really! hate apple

print(test.center(30))
>> '          i really! hate apple              '

print(test.ljust(30))
>> 'i really! hate apple               '

print(test.rjust(30))
>> '          i really! hate apple'

print(test.replace('apple', 'banana')
>> i really! hate banana

'Python > Python__works' 카테고리의 다른 글

set combinations and operators  (0) 2019.06.03
Dictionaries  (0) 2019.06.03
python list comprehension  (0) 2019.05.23
성적 grade 주기  (0) 2019.05.13
dict comprehension  (0) 2019.05.13