English

Give the statement to assign a value "Hello" to the attribute str of class Test and object T1.

Advertisements
Advertisements

Question

Give the statement to assign a value "Hello" to the attribute str of class Test and object T1.

Very Short Answer
Advertisements

Solution

setattr(T1, "str", "Hello")

To create/set str as a class attribute shared by all objects, use:

setattr(Test, "str", "Hello")
shaalaa.com
  Is there an error in this question or solution?
Chapter 3: Classes in Python - EXERCISE [Page 63]

APPEARS IN

CBSE Computer Science with Python [English] Class 12
Chapter 3 Classes in Python
EXERCISE | Q 16. b. | Page 63
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×