class Sample:
pass
sample = Sample()
sample.a = "magic"
print(sample.a)
In the code above, i create an empty class Sample and was able to add set an attribute outside the class definition. Trying to do the same with an instance of str but I encounter AttributeError: 'str' object has no attribute 'a'. Why can't I do the same with an instance of str. Does it have anything to do with str being a primitive type?
sample_string = ""
sample_string.a = "magic"
print(sample_string.a)