# Person.py Copyright (c) Kari Laitinen # http://www.naturalprogramming.com # 2006-05-01 File created. # 2022-12-27 Converted to Python 3. # The corresponding Java program Person.java shows how # data fields of a class are accessed as public fields. # All the data fields and methods (attributes) in Python classes # are public. Python does not have access modifiers such as # public, protected, and private. # This program shows that data attributes (data fields) in # Python classes are not static. Data fields can be dynamically # added during the execution of a program. # After the data attributes (data fields) person_name, year_of_birth, # and country_of_origin have been added and initialized by the # main program, the method print_person_data() finds these attributes # automatically. class Person : def print_person_data( self ) : print( "\n %s was born in %s in %d" % ( self.person_name, self.country_of_origin, self.year_of_birth ) ) # The main program. computing_pioneer = Person() computing_pioneer.person_name = "Alan Turing" computing_pioneer.year_of_birth = 1912 computing_pioneer.country_of_origin = "England" another_computing_pioneer = Person() another_computing_pioneer.person_name = "Konrad Zuse" another_computing_pioneer.year_of_birth = 1910 another_computing_pioneer.country_of_origin = "Germany" computing_pioneer.print_person_data() another_computing_pioneer.print_person_data()