Most people have difficulties to understand classes,
little warriors you're not alone. In this post, I'll try to teach you, how to understand class and apply it in your life!
class Drinks:
kind = "Drink"
def __init__(self,name):
self.name=name
one = Drinks("Orange juice")
two = Drinks("coca-cola")
three = Drinks("water")
print(two.kind)
print(two.name)
- You create the class variable kind to share the attribute.
- We use the init to initialize the instance.
- name its an attribute of an object.
- And all immutable objects: one, two, and three.
Thanks for reading! ;))
Top comments (6)
I love your article because it has given me some insight into Python. Please, recently I got admission at WorldQuant University (WQU) Scientific Computing and Python for Data Science Unit. I have no basis or foundations in Python. The first phase of the course is expected to last for 8 weeks. After reading your article, I realized I have to have a strong foundation in Python, but I do not have. Please, any advice would be much appreciated. Thank You.
@dave its makes me very happy, i'm grateful for this comment .
My pleasure Ma'am. Ma'am, please, can you recommend any material on Python for a beginners
python.nilo.pro.br/ (book)
or
udacity.com/course/introduction-to...
(course)
Thank You, Ma'am
Ma'am, please, the course on Udacity is not free. I listened to the introductory video from Juno. Her explanation of the course made me fall more in love with Python. Honestly speaking I would have loved to join the course, but I do not have money to do so. Since the lockdown was initiated in my country, I lost my job as a teacher and till now, I still do not have a job.
All the same, thank you, Ma'am, for your efforts.