a = 2 # 0x0000001
b = 3 # 0x0000002
c = a + b # 0x0000003규 칙
Camel Case 보다 Snake Case 를 많이 사용함my_name = "Jung"
boolean = True
boolean = False
print(boolean) # Falsef 는 format 을 의미하며, f"~{변수}~" 처럼 사용하면 문자열 안에 변수를 할당할 수 있음.my_name = "jung"
my_age = 12
my_color_eyes = "brown"
print(
f"hello {my_name} you are {my_age} years old and your eyes are {my_color_eyes}"
)print() 도 파이썬의 내장 함수라고 볼 수 있음def 로 함수를 정의할 수 있음. (def 함수명(): 형태)
def 라는 선언자를 사용해야 함.def 로 정의만 해두면 실행되지 않으므로 함수를 실행하기 위해서는 함수명() 으로 실행해주어야 함.tab 또는 space 2번)def say_hello():
print("Hello")say_hello 함수가 받는 name 과 같은 형태는 파라미터(매개변수)라고 하며,“Jung” 과 같이 함수로 전달되는 값은 argument(인자) 라고 함.def say_hello1(name):
print("Hello", name)
say_hello1("jung")jung은 첫번째 파라미터인 user_name에, 10은 두번째 파라미터인 user_age에 전달됨def say_hello(user_name, user_age):
print("Hello", user_name, "you are", user_age, "years old")
say_hello("jung", 10)Default Parameters는 함수에 전달된 인자가 없을 때 기본적으로 사용되는 값임.
user_name = "Anonymous" 처럼 파라미터에 기본값을 설정해주면 됨def say_hello(user_name = "anonymous"):
print("Hello", user_name)
say_hello("jung") # Hello jung
say_hello() # Hello anonymous
# 1개의 인자를 보내야 하므로 에러 발생, 이때 Default Parameters를 사용하면 됨return 키워드를 사용함return 키워드는 함수를 종료시키고 결과값을 반환함 (중요!)to_pay 라는 변수에 tax_calc 함수의 결과값을 할당def tax_calc(money):
return money * 0.35
def pay_tax(tax):
print("Thank you for paying", tax)
to_pay = tax_calc(2000000)
pay_tax(to_pay)
# 또는 pay_tax(tax_calc(2000000)) 처럼 바로 넣어줘도 됨# jucie maker 만들기
def make_juice(fruit):
return f"{fruit}+cup"
def add_ice(juice):
return f"{juice}+ice"
def add_sugar(iced_juice):
return f"{iced_juice}+sugar"
juice = make_juice("apple") # make_juice 함수의 결과값을 juice 변수에 할당
cold_juice = add_ice(juice) # make_juice 함수의 결과값을 add_ice 함수의 파라미터에 전달, add_ice 함수의 결과값을 cold_juice 변수에 할당
perfect_juice = add_sugar(cold_juice)
# cold_juice 변수에 할당된 값을 add_sugar 함수의 파라미터에 전달, add_sugar 함수의 결과값을 perfect_juice 변수에 할당
print(perfect_juice)이 링크를 통해 구매하시면 제가 수익을 받을 수 있어요. 🤗