목차


~~REVEAL night~~

—- https://goo.gl/1c5AJx?.png bg-zoom slide slow —→

>

<fragment-block fade-up>

Python 기본

</fragment-block>

<fragment-block fade-up>
대상: python을 해본 적이 없는 분
</fragment-block>

—→

파이썬으로 할 수 있는 일

<fragment-block fade-up>
<fragment-list>

</fragment-list>
</fragment-block>

—→

<fragment-block fade-up>

파이썬으로 할 수 없는 일

출처: https://wikidocs.net/7

</fragment-block>

—- https://goo.gl/diUgLg?.png bg-zoom slide slow —→

>

# http://repl.it/

실습은 이곳에서 진행합니다.

<fragment-block fade-up>

REPL : Read-Eval-Print Loop의 약자로 스칼라, 파이썬 등 대화형 환경
콘솔에서 컴파일 없이 코드를 입력하고 출력 결과를 확인 할 수 있는 환경

</fragment-block>

—- https://goo.gl/diUgLg?.png bg-zoom slide slow —→

Python3을 선택합니다.vWhg5j

<fragment-block fade-up>
실행화면
4XLb32
</fragment-block>

—→

10 미만의 자연수에서 3과 5의 배수를 구하면 3, 5, 6, 9이다. 이들의 총합은 23이다.

1000 미만의 자연수에서 3의 배수와 5의 배수의 총합을 구하라.

<fragment-block fade-up>
<fragment-block grow>

snippet.python
result = 0
for n in range(1, 1000):
    if n % 3 == 0:
        result += n
    if n % 5 == 0:
        result += n
print(result)

</fragment-block>
</fragment-block>

—→

snippet.python
result = 0
for n in range(1, 1000):
    if n % 3 == 0:
        result += n
    if n % 5 == 0:
        result += n
print(result)

<fragment-block grow>
cU9WZq
</fragment-block>

—- #123 bg-zoom slide slow —→

snippet.python
result = 0
for n in range(1, 1000):
    if n % 3 == 0:
        result += n
    if n % 5 == 0:
        result += n
print(result)

<fragment-block fade-up>

변수에 타입을 지정하지 않아요.

snippet.python
result = 0

</fragment-block>
<fragment-block fade-up>

for, if 에서 소괄호를 사용하지 않아요.

snippet.python
if n % 3 == 0:

</fragment-block>
<fragment-block fade-up>

중괄호{} 대신, :(콜론)을 사용하죠

snippet.python
if n % 5 == 0:
    result += n

</fragment-block>
<fragment-block fade-up>

들여쓰기를 맞춰야 해요.

snippet.python
for n in range(1, 1000):
    if n % 3 == 0:
        result += n

</fragment-block>

—→

주민등록번호를 포함하고 있는 텍스트가 있다.

이 텍스트에 포함된 모든

주민등록번호의 뒷자리를 * 문자로 변경하시오.

<fragment-block fade-up>

snippet.python
data = """
park 800905-1049118
kim  700905-1059119
"""
 
result = []
for line in data.split("\n"):
    word_result = []
    for word in line.split(" "):
        if len(word) == 14 and word[:6].isdigit() and word[7:].isdigit():
            word = word[:6] + "-" + "*******"
        word_result.append(word)
    result.append(" ".join(word_result))
print("\n".join(result))

출처: https://wikidocs.net/1642

</fragment-block>

—- #323 bg-zoom slide slow —→

주민등록번호를 포함하고 있는 텍스트가 있다.

이 텍스트에 포함된 모든

주민등록번호의 뒷자리를 * 문자로 변경하시오.

<fragment-block fade-up>

정규표현식을 사용하면

</fragment-block>

<fragment-block fade-up>

snippet.python
import re 
 
data = """
park 800905-1049118
kim  700905-1059119
"""
 
pat = re.compile("(\d{6})[-]\d{7}")
print(pat.sub("\g<1>-*******", data))

</fragment-block>

—→


관련 문서