r/PythonLearning
•
u/shubham_555
•
Sep 13 '26
•
1
Showcase The Bank Project
Last Post - https://www.reddit.com/r/PythonLearning/s/kGqwMS9HUH
Github Repo - https://github.com/Dev-4-All/bank.git
242
Upvotes
View all comments
Show parent comment
1
u/FoolsSeldom Sep 13 '26 edited Sep 13 '26
Yes, basically.
Here's an example rewrite of your code to illustrate more:
Notes:
dataclassis a kind ofclasswhere there's less boilerplate code for you to writeclass, instead of variables, we have attributes, but they are basically the same otherwiseIn Python, we start a name with an underscore (or two underscores) to indicate that it is private i.e. should not be generally used outside the scope of the code that defines it but note that Python (unlike some languages) does not enforce this, it is up to the programmer to act accordingly
account._balancebut instead you go via the property methodbalancewhich you use as if it is a regular attribute (later, the method could be updated to take account of pending payments or other things that might impact the current balance)try/exceptin your original code, and this code creates some custom exceptions to deal with some bank account issuesNote that the methods (functions defined inside a class) don't assume interaction with the user
classsuch as account number, name, type, etcis_logged_invariable as an attribute in theclassinstead as it is account specificA
class(ordataclass) definition is just a mould (template) for a new Python object with the data structures and behaviours provided in the definitionclassdefinition in Python is used to create instances of theclass- in this code, only one instance is created, and it is assigned to the variableaccountclassmethods have a reference toself, which just means whichever instance of theclassthe method has been called for