GyaanSetu WebDev’s Post

𝗧𝗵𝗶𝘀 𝗜𝘀 𝗗𝗮𝘆 𝟲𝟯 𝗼𝗳 #𝟭𝟬𝟬𝗗𝗮𝘆𝘀𝗢𝗳𝗖𝗼𝗱𝗲 I continued my Python refresher and introduced Django. Yesterday, I covered Python basics. Today, I dove into functions and object-oriented programming \(OOP\) because these are essential for understanding Django. You define a function in Python using the def keyword. For example: - def greet\(name\): return f"Hello, \{name\}!" - print\(greet\("Haris"\)\) # Hello, Haris! Functions have powerful features: - You can assign default values to parameters - Use \*args to collect extra positional arguments into a tuple - Use \*\*kwargs to collect extra keyword arguments into a dictionary You can use these together. The order matters: regular args, \*args, \*\*kwargs. Python is fully object-oriented. You define classes and use \_\_init\_\_ as the constructor. - class Person: - def \_\_init\_\_\(self, name, age\): self.name = name, self.age = age - def introduce\(self\): return f"Hi, I'm \{self.name\} and I'm \{self.age\} years old." I also looked at how Django structures projects. A project is the entire web application, and you organize functionality into smaller units called apps. - Each app handles one specific part of your project - You create an app using python manage.py startapp posts This keeps your code modular and clean. Source: https://lnkd.in/g4YgFWMu

To view or add a comment, sign in

Explore content categories