Skip to content

Commit 8cafc28

Browse files
committed
2일차
1 parent 4940eea commit 8cafc28

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

day1_4+1_5.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# function 정의하기
2+
3+
def say_hello(): #파이썬은 : 들여쓰기로 함수를 표현한다.
4+
print("hello")
5+
6+
say_hello() #함수 실행
7+
8+
# 함수 인자 전달하기(positional argument : 의존적인 인자)
9+
def say_bye(who):
10+
print("bye", who)
11+
12+
say_bye("mr_kim")
13+
say_bye(True)
14+
say_bye(33)
15+
say_bye("3")
16+
17+
# 인자 복수개 전달하기
18+
def plus(a,b):
19+
print(a+b)
20+
21+
def minus(a,b):
22+
print(a-b)
23+
24+
plus(2,4)
25+
minus(2,4)
26+
27+
# 인자 중 하나에 상수 전달하기..dafault value
28+
def plus2(a,b=2):
29+
print(a+b)
30+
plus2(2)
31+
32+
def hola(name = "docker1"):
33+
print("hello", name)
34+
35+
hola()
36+
hola("doctor kim") # 디폴트 값 덮어쓰기 가능

day1_6.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def plus(a,b):
2+
return a+b
3+
4+
def print_plus(a,b):
5+
print(a+b)
6+
7+
r_res = plus(2,3) # return 에 의해 5가 저장
8+
p_res = print_plus(2,3)
9+
print(p_res, r_res) # p_res는 Node r_res는 5 가 출력된다.
10+
# return 값이 함수의 최종 결과값으로 치환된다.
11+
12+
13+
def return_plus(a,b):
14+
return a+b
15+
print("kalkafdklsajflsdfjskdfjasdfjl",True)
16+
17+
return_res = return_plus(2,4)
18+
print(return_res) # 함수 안의 print는 실행되지 않았다. return 하는 순간 함수는 종료되기 때문.
19+
#오직 한번의 return만 존재할 수 있음. 따라서 리턴 아래는 무효화.

day1_7.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# keyword argument : 인자가 위치에 따라 정해지는게 아닌 이름으로 쌍을 이룸
2+
# 인자 개수가 많아질 때 유용하다.
3+
4+
def plus(a,b):
5+
return a-b
6+
7+
result = plus(b=30, a=1) #인자 위치가 아닌, 이름에 따라 결정되었음
8+
print(result)
9+
10+
####
11+
#string 안에 변수를 포함시키고 싶다면 f(format)를 앞에 붙이고 변수를 {}감싼다
12+
def say_hello(name, age):
13+
return f"hello {name} u are {age} years old"
14+
15+
hello = say_hello(age="14",name="david") #키워드 인자
16+
print(hello)
17+
18+
#혹은 + 연산자로 string을 이어주는 방법도 있다.
19+
def say_hola(name, age):
20+
return "hello " + name + " u are " + age + " years old"
21+
22+
hola = say_hola("lucy","29")
23+
print(hola)

day1_8.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# 과제1
2+
3+
"""
4+
As you can see, the code is broken.
5+
Create the missing functions, use default arguments.
6+
Sometimes you have to use 'return' and sometimes you dont.
7+
Start by creating the functions
8+
"""
9+
def is_on_list(day_list,day):
10+
return day in day_list
11+
12+
def get_x(day_list,day):
13+
return day_list[day]
14+
15+
def add_x(day_list,day):
16+
return day_list.append(day)
17+
18+
def remove_x(day_list,day):
19+
return day_list.remove(day)
20+
21+
# \/\/\/\/\/\/\ DO NOT TOUCH AREA \/\/\/\/\/\/\ #
22+
23+
days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
24+
25+
print("Is Wed on 'days' list?", is_on_list(days, "Wed"))
26+
27+
print("The fourth item in 'days' is:", get_x(days, 3))
28+
29+
add_x(days, "Sat")
30+
print(days)
31+
32+
remove_x(days, "Mon")
33+
print(days)
34+
35+
36+
# /\/\/\/\/\/\/\ END DO NOT TOUCH AREA /\/\/\/\/\/\/\ #
37+
38+
39+
40+

0 commit comments

Comments
 (0)