r/learnpython • u/GingerSkwatch • Feb 23 '21
Classes. Please explain like I’m 5.
What exactly do they do? Why are they important? When do you know to use one? I’ve been learning for a few months, and it seems like, I just can’t wrap my head around this. I feel like it’s not as complicated as I’m making it, in my own mind. Thanks.
229
Upvotes
View all comments
Show parent comment
5
u/[deleted] Feb 24 '21 edited Feb 24 '21
When you define a function whose parameter has
=something, that becomes the default value if you do not pass an argument in.Try running these to see what that means.
The reason I added a
=Nonehere is because if this were actually a function used by an ATM or bank, then when you created an account, you'd probably want to set thedate_openedvalue to the current timestamp (hence thedatetime.datetime.today()). But I gave the option of passing in something else in case you wanted to retroactively create an account for someone.