“Python GetAttr Funkcja” Kod odpowiedzi

Python Getattr

class Student:
  marks = 88
  name = 'Sheeran'

person = Student()

name = getattr(person, 'name')
print(name)

marks = getattr(person, 'marks')
print(marks)

# Output: Sheeran
#         88
John Appleseed

Python GetAttr Funkcja

class Student:
    name = 'John'
    age  = 24
  
student = Student()
  
print('Student name: ', getattr(student, 'name'))
print('Student age: ', getattr(student, 'age'))
  
# Output
# Student name:  John
# Student age:  24
Glorious Gnat

Odpowiedzi podobne do “Python GetAttr Funkcja”

Pytania podobne do “Python GetAttr Funkcja”

Więcej pokrewnych odpowiedzi na “Python GetAttr Funkcja” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu