ββββπ₯ππ΅β β
try:
cal=calculator(20,r)
print(cal.div())
except ZeroDivisionError:
print('0μΌλ‘ λλ μ μμ΅λλ€')
except:
print('μ«μλ§ μ
λ ₯ κ°λ₯ν©λλ€')
-> μ΄λ κ² μΈμ€ν΄μ€ μ΄νλ₯Ό λ€ κ°μΈλ κ² λ³΄λ¨
ν΄λμ€ μμ μ μλ ν¨μ κ°κ°μμ λ°μνλ μλ¬λκΉ κ°κ°μ ν¨μλ₯Ό μμͺ½μ μ°λ κ²μ΄ λ μ’λ€
->κ·Έλ¦¬κ³ νμνλ€λ©΄ try νλμ except μ¬λ¬κ° μ€μ€μ΄ λ¬μ μΈ μλ μλ€
def print_user_input(message): #parameter
print(message)
print_user_input('hello sparta') #arg
def main(n1,n2,*args,**kwargs)
print(n1) #1
print(n2) #2
print(args) #(3,4,5,6,7,8,9)->ννλ‘!!
print(kwargs) #{}->λΉ λμ
λ리λ‘!!
main(1,2,3,4,5,6,7,8,9)
a = [1,2,3,4]
print(*a) #1,2,3,4
--> μμμ μ¬μ©ν *args, **kwargsλ μΈν¨νΉ
#regular expression: μ κ·μ
import re
# μνλ²³, μ«μλ‘ μμν΄μΌ νλ©° . λ€μ 2μμ μνλ²³μ΄ μμΌ νλ€.
email_regex = re.compile(r'([A-Za-z0-9]+[.-_])*[A-Za-z0-9]+@[A-Za-z0-9-]+(\.[A-Z|a-z]{2,})+')
class Attendance:
count = 0
def attendance(self):
self.count += 1
#λ°μ½λ μ΄ν°!! νλ‘νΌν°μ μΈν°
@property
def attendance_count(self):
return self.count
class Profile(Attendance):
def __init__(self, name, age, email):
self.__name = name # __λ₯Ό λΆμ¬μ£Όλ©΄ class λ΄λΆμμλ§ μ¬μ©νκ² λ€λ λ»
self.__age = age #_λ₯Ό λΆμ¬μ£Όλ©΄ class λ΄λΆμμλ§ μ¬μ©νμλ μ½μ(κ°μ x νμ§λ§ λ°μμ μ¬μ©μ μΆν μ€λ₯λ°μκ°λ₯)
self.__email = email
@property # μ½κΈ° μ μ© μμ±- νΈμΆμ μλκ° μ€νλ¨
def name(self):
return self.__name
@name.setter # μ°κΈ° μ μ© μμ±- κ°μ μ€μ ν λ μλκ° μ€νλ¨
def name(self, name):
if isinstance(name, str) and len(name) >= 2:
print("μ΄λ¦μ 2μ μ΄μ λ¬Έμλ§ μ
λ ₯ κ°λ₯ν©λλ€.")
else:
self.__name = name
@property
def age(self):
return self.__age
@age.setter
def age(self, age):
if isinstance(age, int):
self.__age = age
else:
print("λμ΄μλ μ«μλ§ μ
λ ₯ κ°λ₯ν©λλ€.")
@property
def email(self):
return self.__email
@email.setter
def email(self, email):
if re.fullmatch(email_regex, email):
self.__email = email
else:
print("μ ν¨νμ§ μμ μ΄λ©μΌμ
λλ€.")
def attendance(self): # override
super().attendance() # λΆλͺ¨ λ©μλ μ¬μ©νκΈ°
self.count += 1
def __str__(self):
return f"{self.__name} / {self.__age}"
def __repr__(self):
return f"{self.__name}"
return print()
-> κ°μ΄ μ°μ§ μλλ€ λ μ€ νλλ§! 리ν΄ν΄μ€μ νλ¦°νΈλ λ€μ μ°¨λ‘μ νκ±°λ νλ¦°νΈλ₯Ό ν΄μ ν¨μ μ€ννλ©΄ μλμΌλ‘ νλ¦°νΈ λλλ‘ νλΉ
1)
def add(a,b):
print(a+b)
return
2)
def add(a,b):
print(a+b)
-> 1),2) λκ°μ§ κ²½μ° λͺ¨λ noneμ 리ν΄νλ€
def add(a,b):
print(a+b)
add()
-> missing 2 arguments
def set_profile(**kwargs):
profile = {}
profile["name"] = kwargs.get("name", "-")
profile["gender"] = kwargs.get("gender", "-")
profile["birthday"] = kwargs.get("birthday", "-")
profile["age"] = kwargs.get("age", "-")
profile["phone"] = kwargs.get("phone", "-")
profile["email"] = kwargs.get("email", "-")
return profile
user_profile = {
"name": "lee",
"gender": "man",
"age": 32,
"birthday": "01/01",
"email": "python@sparta.com",
}
print(set_profile(**user_profile))
""" μλ μ½λμ λμΌ, νμ΄μ μ΄ κ² λΏμ
profile = set_profile(
name="lee",
gender="man",
age=32,
birthday="01/01",
email="python@sparta.com",
)
"""