Python class attribute assignment

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Python class attribute assignment



I'm new to Python, and I was wondering why I can't change the attribute for a class instance using a function, if I pass the instance as a function parameter
For example, if I had:


class sol:
def __init__(self):
self.val = 0

def fun1(obj, attrib):
obj[attrib] = 1

newSol = sol()

fun1(newSol, "val")



Why can't fun1 change the object attribute? Is there a way to change it, or is the "val" attribute immutable?









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard