class CookieFreme() #C.F라는 이름의 class 선언
def set_cookie_name(self,name):
self.name = name
cookie1.set_cookie_name("cookie1") #메소드 첫번째 인자 self는 무시됨.
cookie2.set_cookie_name("cookie2")
print(cookie.name1) > cookie1
print(cookie.name2) > cookie2
cookie1 = CookieFrame("cookie1") > 생성 된 과자의 이름은 cookie1 입니다!
cookie2 = CookieFrame("cookie2") > 생성 된 과자의 이름은 cookie2 입니다!
from pprint import pprint
class Profile:
def __init__(self):
self.profile = {
"name": "-",
"gender": "-",
"birthday": "-",
"age": "-",
"phone": "-",
"email": "-",
}
def set_profile(self, profile):
self.profile = profile
def get_profile(self):
return self.profile
profile1 = Profile()
profile2 = Profile()
profile1.set_profile({
"name": "lee",
"gender": "man",
"birthday": "01/01",
"age": 32,
"phone": "01012341234",
"email": "python@sparta.com",
})
profile2.set_profile({
"name": "park",
"gender": "woman",
"birthday": "12/31",
"age": 26,
"phone": "01043214321",
"email": "flask@sparta.com",
})
pprint(profile1.get_profile())
pprint(profile2.get_profile())
# result print
"""
{
'name': 'lee',
'gender': 'man',
'birthday': '01/01',
'age': 32,
'phone': '01012341234',
'email': 'python@sparta.com'
}
{
'name': 'park',
'gender': 'woman',
'birthday': '12/31',
'age': 26,
'phone': '01043214321',
'email': 'flask@sparta.com'
}
"""
print(a) > 10
print(b) > 15
a 담긴 자료형의 속성에 따라 출력 값이 달라짐.
immutable = "String is immutable!!"
mutable = ["list is mutable!!"]
string = immutable
list_ = mutable
string += " immutable string!!"
list_.append("mutable list!!")
print(immutable) > String is immutable!!
print(mutable) > ['list is mutable!!', 'mutable list!!']
print(string) > String is immutable!! immutable string!!
print(list_) > ['list is mutable!!', 'mutable list!!']
2번째 mutable 이 조금 특이함. 상식적으로는 ["list is mutable!!"]이 나올 것 같지만, ['list is mutable!!', 'mutable list!!']가 나온다.
mutable = ["list is mutable!!"]
list_ = mutable
list_.append("mutable list!!")
print(mutable) > ['list is mutable!!', 'mutable list!!']
#str과 비교
a = '123'
b = a
c = ["a"]
d= c
str은 a,b가 각각 '123'을 바라보는 것이고 list는 c,d가 같은 ['a']를 바라본다고 생각하면 됨.