6. BY. PNY
귀도 반 로섬(Guido van Rossum)이 심심해서 제작
1991년 발표
객체 지향 언어
평소 좋아한 코미디에서 따옴 ▶
https://ko.wikipedia.org/wiki/파이썬 6
7. BY. PNY
7
“ 하나 이상의 해결법이 존재한다 ”
“가장 아름다운 하나의 답이 존재한다 ”
Beautiful is better than ugly
Explicit is better than implicit
Simple is better than complex
13. BY. PNY
a = 1
b = "hello"
print type(a)
print type(b)
<type ‘int’>
<type ‘str’>
javascript 등과 같은 Dynamic Typing
13
14. BY. PNY
if 4 in [1, 2, 3, 4] :
print “There is 4”
→ “ 만약 4가 [1, 2, 3, 4]안에 있다면 “There is 4”를 출력해라. ”
영어 문장을 읽는 듯한 착각!
14
15. BY. PNY
for (int i=1; i<4; i++)
cout << i << endl;
for i in range(1, 4):
print i
C++
Python
15
16. BY. PNY
for i in range(1, 4):
print i
print “Wow”;
print “Fantastic Baby”
‘ { } ’가 아닌 들여쓰기로 범위(scope) 구분
세미콜론(;) 사용은 자유
한 라인에 쓸 경우 : 세미콜론 필요
16
print “Wow”; print “Fantastic Baby”
17. BY. PNY
public class HelloWorld {
public static void main (String[] args) {
System.out.println("Hello world!");
}
}
print “Hello world!”
Java
Python
17
18. BY. PNY
public class Employee
{
private String myEmployeeName;
private int myTaxDeductions = 1;
private String myMaritalStatus = "single";
//--------- constructor #1 -------------
public Employee(String employeeName)
{
this(employeeName, 1);
}
//--------- constructor #2 -------------
public Employee(String employeeName, int taxDeductions)
{
this(employeeName, taxDeductions, “single”);
}
//--------- constructor #3 -------------
public Employee(String employeeName,
int taxDeductions,
String maritalStatus)
{
this.myEmployeeName = employeeName;
this.myTaxDeductions = taxDeductions;
this.myMaritalStatus = maritalStatus;
}
...
class Employee():
def __init__(self
, employeeName
, taxDeductions = 1
, maritalStatus = "single"
):
self.employeeName = employeeName
self.taxDeductions = taxDeductions
self.maritalStatus = maritalStatus
...
Java Python
# 참고
# 한줄 주석
“““
여러줄 주석
”””
# 생성자 __init__
# 소멸자 __del__
18
21. BY. PNY
t1 = ()
t2 = (1, ) #한 개의 요소만을 넣을 때 ,필요
t3 = (1, 2, 3)
t4 = 1, 2, 3 #괄호 생략 가능
t5 = ('a', 'b', ('ab', 'cd'))
리스트의 [ 와 ] 대신 튜플은 ( 와 )로 둘러싼다
리스트는 그 값을 생성, 삭제, 수정이 가능하지만
튜플은 그 값을 변화시킬 수 없다.
이외에는 리스트와 동일
21
22. BY. PNY
# {Key1:Value1, Key2:Value2, Key3:Value3 ...}
dic = {'name':'pey', 'phone':'0119993323',
'birth': '1118'}
key, value의 형태 (흔히 아는 Hash의 개념)
key를 통해 value를 얻을 수 있다.
중복 key 사용은 자제 (나머지가 무시됨)
key에는 리스트는 사용할 수 없지만 튜플은 가능하다.
(변하지 않는 값이기 때문)
22
23. BY. PNY
s1 = set([1, 2, 3])
s2 = set(“Hello”)
print s1
print s2
집합에 관련된 것들을 처리하기에 좋음
(교집합, 합집합, 차집합 등 지원)
중복을 허용하지 않는다.
순서가 없다. (indexing 불가)
23
set([1, 2, 3])
set([‘H’, ‘e’, ‘l’, ‘o’])
32. BY. PNY
RETURN에서 진행한 속성 Python Game Study
2016년 1월 6, 7, 8, 11, 12일 - 총 5일
32
33. BY. PNY
1일차 : python 문법 공부 & 숫자 야구 게임
2일차 : 똥 피하기 게임
3일차 : 슈팅 게임(형식은 자유)
4~5일차 : 자유 주제
33
34. BY. PNY
코드 아카데미(ko) - python
https://www.codecademy.com/ko/tracks/python-ko
34
35. BY. PNY
35
http://www.pygame.org/
python 게임 라이브러리
2000년 출시
안드로이드 지원(ios 미지원)
# 1 - pygame 라이브러리를 임포트 한다.
import pygame
from pygame.locals import *
# 2 - 게임을 초기화한다.
pygame.init()
width, height = 640, 480
screen = pygame.display.set_mode((width, height))
# 3 - 이미지를 불러온다.
player =
pygame.image.load("resources/images/dude.png")
# 4 - 무한 루프
while 1:
# 5 - 화면 그릴 준비. 화면을 검게 만든다.
screen.fill(0)
# 6 - 플레이어를 (100, 100)에 그린다.
screen.blit(player, (100, 100))
# 7 - 화면을 업데이트한다.
pygame.display.update()
# 8 - 발생한 이벤트들을 가져와 처리하는 루프
for event in pygame.event.get():
# x 버튼을 클릭하여 종료하려고 하면
if event.type==pygame.QUIT:
# pygame 라이브러리 종료 후 프로그램 종료
pygame.quit()
exit(0)
https://en.wikipedia.org/wiki/Pygame
http://www.raywenderlich.com/24252/beginning-game-programming-for-teens-with-python?utm_content=bufferfd9c0&utm_source=buffer&utm_medium=twitter&utm_campaign=Buffer