진짜코딩하며배우는파이썬(3)
-
type()으로 자료형 확인하기 + 객체 개념
우선 JAVA 위주로 공부하다가 Python도 함께 공부하니 둘 다 객체지향 언어(Class 사용)라는 점에서 닮은 점이 많았다. class Coffee : pass print(type(3), ":3") print(type(4), ":4") print(type(3.14), ":3.14") print(type(3.15),"3.15") print(type(True),":True") print(type(False),":False") print(type("Hello"),":Hello") print(type([1,2,3,4]),": [1,2,3,4]") print(type(Coffee()), ":Coffee()") print(type(Coffee), ":Coffee") 실행 결과 :3 :4 :3.14 3.15 :..
2021.08.31 -
둘 이상의 함수 반환 값
진코파를 공부하던 도중, '둘 이상의 함수 반환 값' 코드에서 궁금한 점이 있어서 내가 생각한 방법으로 코드를 작성해보니 같은 결과가 나왔다. 책의 내용 ) h(x,y) def h(x,y) : return x+y x=2 y=2 z=h(x,y) print(z) 내가 작성한 코드 ) z=x+y def h(x,y) : return x+y x = 2 y = 2 z = x+y print(z) 책에서는 h의 좌표값을 z 변수에 대입하였지만, 나는 x와 y 변수를 더한 값을 z에 넣는 방법으로 선택했다. h(x,y)는 함수 h에 2 값을 갖는 x,y를 인자로 넣는다는 뜻이다. 결국 2 라는 값 2개를 넘겨받은 함수 z는 결과 값으로 4를 내어주며 4는 z변수에 할당된다. 그래도 둘의 결과는 4로 동일했다.
2021.08.31 -
커피 타는 프로그램 작성해 보기
def pour(cup, ingredient): print("pour", ingredient, "into", cup) return def stir(cup): print("stir", cup) return def put(cup, whipping_cream): print("put", whipping_cream, "on", cup) return def spread(whipping_cream, cocoa_powder): print("spread", cocoa_powder, "on", whipping_cream) return cup = "cup" chocolate_sauce = "chocolate sauce" espresso = "espresso" warm_milk = "warm milk" whipping_cre..
2021.08.31