Advertisements
Advertisements
प्रश्न
Predict the output of the given class-attribute program.
class Match:
' "Runs and Wickets" '
runs=281
wickets=5
def __init__(self,runs,wickets):
self.runs=runs
self.wickets=wickets
print " Runs scored are : ",runs
print "Wickets taken are : ",wickets
print "Test.__do__:", Match.__doc__
print "Test.__name__:", Match.__name__
print "Test.__module__:", Match.__module__
print "Test.__bases__:", Match.__bases__
print "Test.__dict__:", Match.__dict__कोड लेखन
Advertisements
उत्तर
The question uses Python 2 print syntax. In Python 3, it must be written using print().
No object of Match is created, so the messages about runs and wickets are not printed. The built-in class attributes produce the following values:
Match.__doc__: Runs and Wickets
Match.__name__: Match
Match.__module__: __main__
Match.__bases__: ()
Match.__dict__: mappingproxy({...})
Match.__dict__ contains the class namespace, including __module__, __doc__, runs, wickets and __init__. Its exact display is implementation-dependent because the function object includes a memory address.
class Match:
"""Runs and Wickets"""
runs = 281
wickets = 5
def __init__(self, runs, wickets):
self.runs = runs
self.wickets = wickets
print("Runs scored are:", runs)
print("Wickets taken are:", wickets)
print("Match.__doc__:", Match.__doc__)
print("Match.__name__:", Match.__name__)
print("Match.__module__:", Match.__module__)
print("Match.__bases__:", Match.__bases__)
print("Match.__dict__:", Match.__dict__)shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
