|
@@ -7,8 +7,7 @@ class Person:
|
|
|
name = 'Ivan'
|
|
|
age = 30
|
|
|
|
|
|
-
|
|
|
-def main():
|
|
|
+def teset_attr():
|
|
|
car = Car()
|
|
|
print(type(car))
|
|
|
|
|
@@ -17,6 +16,9 @@ def main():
|
|
|
print(Person.name)
|
|
|
print(Person.__dict__)
|
|
|
|
|
|
+ # Наличие атрибута
|
|
|
+ print(hasattr(Person, 'sex'))
|
|
|
+
|
|
|
# Получить атрибут
|
|
|
print(getattr(Person, 'name'))
|
|
|
Person.name = 'Misha'
|
|
@@ -40,5 +42,56 @@ def main():
|
|
|
|
|
|
print(Person.z)
|
|
|
|
|
|
+def test_attr_2():
|
|
|
+
|
|
|
+ class Empty:
|
|
|
+ pass
|
|
|
+
|
|
|
+ my_list = [
|
|
|
+ ('apple', 23),
|
|
|
+ ('banana', 80),
|
|
|
+ ('cherry', 13),
|
|
|
+ ('date', 10),
|
|
|
+ ('elderberry', 4),
|
|
|
+ ('fig', 65),
|
|
|
+ ('grape', 5),
|
|
|
+ ('honeydew', 7),
|
|
|
+ ('kiwi', 1),
|
|
|
+ ('lemon', 10),
|
|
|
+ ]
|
|
|
+
|
|
|
+ for i in my_list:
|
|
|
+ setattr(Empty, i[0], i[1])
|
|
|
+
|
|
|
+ print(Empty.__dict__)
|
|
|
+ # print(Empty.__dict__())
|
|
|
+
|
|
|
+def test_attr_3(cl, name: str):
|
|
|
+ return name in cl.__dict__
|
|
|
+
|
|
|
+def test_attr_4():
|
|
|
+
|
|
|
+ class Person:
|
|
|
+ name = "John Smith"
|
|
|
+ age = 30
|
|
|
+ gender = "male"
|
|
|
+ address = "123 Main St"
|
|
|
+ phone_number = "555-555-5555"
|
|
|
+ email = "johnsmith@example.com"
|
|
|
+ is_employed = True
|
|
|
+
|
|
|
+ names = input().split()
|
|
|
+
|
|
|
+ for i in names:
|
|
|
+ print(i,'-', 'YES' if hasattr(Person, i.lower()) else 'NO', sep='')
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def main():
|
|
|
+ # teset_attr()
|
|
|
+ # test_attr_2()
|
|
|
+ # print(test_attr_3(Car, 'model'))
|
|
|
+ test_attr_4()
|
|
|
+
|
|
|
if __name__ == '__main__':
|
|
|
main()
|