How do these 2 classes differ?
class A(): x=3 class B(): def __init__(self): self.x=3
Is there any significant difference?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A.xis a class variable.B‘sself.xis an instance variable.i.e.
A‘sxis shared between instances.It would be easier to demonstrate the difference with something that can be modified like a list:
Output