<jupyter_start><jupyter_text>직접 해보세요! 문자열 추출하기(183쪽)<jupyter_code>word = 'grail'
sent = 'a scratch'
print(word[0])
print(sent[0])
print(word[0:3])<jupyter_output>gra<jupyter_text>---<jupyter_code>print(sent[-1])
print(sent[-9:-8])
print(sent[0:-8])<jupyter_output>a<jupyter_text>알아두면 좋아요! 전체 문자열을 추출할 때 음수를 사용하면 안 됩니다(184쪽)<jupyter_code>print(sent[2:-1])
print(sent[-7:-1])
s_len = len(sent)
print(s_len)
print(sent[2:s_len])<jupyter_output>scratch<jupyter_text>직접 해보세요! 왼쪽이나 오른쪽 범위를 지정하지 않고 문자열 추출하기(185쪽)<jupyter_code>print(word[0:3])
print(word[ :3])
print(sent[2:len(sent)])
print(sent[2: ])
print(sent[ : ])
print(sent[::2])<jupyter_output>asrth<jupyter_text>직접 해보세요! join, splitlines, replace 메서드 실습하기(188쪽)  1. join 메서드<jupyter_code>d1 = '40°' 
m1 = "46'" 
s1 = '52.837"' 
u1 = 'N'

d2 = '73°' 
m2 = "58'" 
s2 = '26.302"' 
u2 = 'W'
coords = ' '.join([d1, m1, s1, u1, d2, m2, s2, u2])
print(coords)<jupyter_output>40° 46' 52.837" N 73° 58' 26.302" W<jupyter_text>2. splitlines 메서드<jupyter_code>multi_str = """Guard: What? Ridden on a horse?
King Arthur: Yes!
Guard: You're using coconuts!
King Arthur: What?
Guard: You've got ... coconut[s] and you're bangin' 'em together. 
""" 
print(multi_str)
multi_str_split = multi_str.splitlines() 
print(multi_str_split)
guard = multi_str_split[::2] 
print(guard)<jupyter_output>['Guard: What? Ridden on a horse?', "Guard: You're using coconuts!", "Guard: You've got ... coconut[s] and you're bangin' 'em together. "]<jupyter_text>4. replace 메서드<jupyter_code>guard = multi_str.replace("Guard: ", "").splitlines()[::2] 
print(guard)<jupyter_output>['What? Ridden on a horse?', "You're using coconuts!", "You've got ... coconut[s] and you're bangin' 'em together. "]<jupyter_text>직접 해보세요! 문자열 포매팅하기(190쪽)<jupyter_code>var = 'flesh wound' 
s = "It's just a {}!"

print(s.format(var))
print(s.format('scratch'))
s = """Black Knight: 'Tis but a {0}.
King Arthur: A {0}? Your arm's off!
""" 
print(s.format('scratch'))
s = 'Hayden Planetarium Coordinates: {lat}, {lon}' 
print(s.format(lat='40.7815° N', lon='73.9733° W'))<jupyter_output>Hayden Planetarium Coordinates: 40.7815° N, 73.9733° W<jupyter_text>직접 해보세요! 숫자 데이터 포매팅하기(191쪽)<jupyter_code>print('Some digits of pi: {}'.format(3.14159265359))
print("In 2005, Lu Chao of China recited {:,} digits of pi".format(67890))
print("I remember {0:.4} or {0:.4%} of what Lu Chao recited".format(7/67890))
print("My ID number is {0:05d}".format(42))<jupyter_output>My ID number is 00042<jupyter_text>직접 해보세요! % 연산자로 포매팅하기(192쪽)<jupyter_code>s = 'I only know %d digits of pi' % 7 
print(s)
print('Some digits of %(cont)s: %(value).2f' % {'cont': 'e', 'value': 2.718})<jupyter_output>Some digits of e: 2.72<jupyter_text>알아두면 좋아요! f-strings로 포매팅 사용하기(193쪽)<jupyter_code>var = 'flesh wound' 
s = f"It's just a {var}!" 
print(s)
lat='40.7815°N' 
lon='73.9733°W' 
s = f'Hayden Planetarium Coordinates: {lat}, {lon}' 
print(s)<jupyter_output>Hayden Planetarium Coordinates: 40.7815°N, 73.9733°W<jupyter_text>직접 해보세요! 정규식으로 전화번호 패턴 찾기(196쪽)<jupyter_code>import re

tele_num = '1234567890'
m = re.match(pattern='\d\d\d\d\d\d\d\d\d\d', string=tele_num) 
print(type(m))
print(m)
print(bool(m))
if m:
    print('match') 
else:
    print('no match')
print(m.start())
print(m.end())
print(m.span())
print(m.group())
tele_num_spaces = '123 456 7890'
m = re.match(pattern='\d{10}', string=tele_num_spaces) 
print(m)
if m:
    print('match') 
else:
    print('no match')
p = '\d{3}\s?\d{3}\s?\d{4}' 
m = re.match(pattern=p, string=tele_num_spaces) 
print(m)
tele_num_space_paren_dash = '(123) 456-7890' 
p = '\(?\d{3}\)?\s?\d{3}\s?-?\d{4}' 
m = re.match(pattern=p, string=tele_num_space_paren_dash) 
print(m)
cnty_tele_num_space_paren_dash = '+1 (123) 456-7890' 
p = '\+?1\s?\(?\d{3}\)?\s?\d{3}\s?-?\d{4}' 
m = re.match(pattern=p, string=cnty_tele_num_space_paren_dash) 
print(m)<jupyter_output><_sre.SRE_Match object; span=(0, 17), match='+1 (123) 456-7890'><jupyter_text>알아두면 좋아요! compile 메서드로 정규식 메서드 사용하기(200쪽)<jupyter_code>p = re.compile('\d{10}') 
s = '1234567890' 
m = p.match(s) 
print(m)<jupyter_output><_sre.SRE_Match object; span=(0, 10), match='1234567890'>
{'fraction_non_alphanumeric': 0.2, 'fraction_numerical': 0.07222222222222222, 'mean_word_length': 6.042517006802721, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '131951', 'license': 'MIT', 'n_tokens_mistral': 2231, 'n_tokens_neox': 2183, 'n_words': 370, 'path': 'DoitPandas_Resource/notebook/09_done.ipynb', 'repo_name': 'gi3265/SOpt_DoItPandas', 'size': '4140'}