Back to articles
Day 64 of #100DaysOfCode — Python Refresher Part 4 + Introduction to Models in Django

Day 64 of #100DaysOfCode — Python Refresher Part 4 + Introduction to Models in Django

via Dev.toM Saad Ahmad

Yesterday I covered functions in depth: *args , **kwargs , decorators, lambdas. Today I moved into OOP in Python. I already knew OOP from C++, and I know how classes work in JavaScript too, so for today, Day 64, was mostly about learning the Python way of doing things. At the end, I also took a first look at Django Models. OOP in Python Classes and Objects A class is a blueprint. An object is an instance of that blueprint. class Car : def __init__ ( self , brand , model ): self . brand = brand self . model = model def describe ( self ): return f " { self . brand } { self . model } " my_car = Car ( " Toyota " , " Corolla " ) print ( my_car . describe ()) # Toyota Corolla __init__ is the constructor. It runs automatically when you create an object. self is the reference to the current instance, similar to this in JavaScript and C++. Instance vs Class Attributes Instance attributes are unique to each object. Class attributes are shared across all instances. class Employee : company = " Te

Continue reading on Dev.to

Opens in a new tab

Read Full Article
1 views

Related Articles