Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Class Instantiation Increment?

$
0
0
I'm new to Python and programming in general. Reading a few tutorials online and learning what I can.
class NewUser:
    uid = 0
    def __init__(self, username):
        self.username = username
        self.uid += 1

x = NewUser("User1")
print(x.username)
print(x.uid)

y = NewUser("User2")
print(y.username)
print(y.uid)



My question is, how do I make uid increment on each instance of NewUser?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>