Day 26 of #100DaysOfCode👩💻🚀 Today I learned about Getter, Setter, and 3 types of methods in Python OOP. Getter & Setter methods: Getters are used to access private data safely → `get_name()` Setters are used to update private data with validation → `set_age()` They help protect data and add control over how variables are read or changed. 3 Types of Methods in Python: 1. Instance method → Uses `self`, works with object data. Called by objects. 2. Class method → Uses `@classmethod` and `cls`, works with class variables. Called by class. 3. Static method → Uses `@staticmethod`, doesn’t use `self` or `cls`. Like a normal function inside class. One more step toward writing clean, secure OOP code. Special thanks to the CEO G.R NARENDRA REDDY Sir for constant guidance and motivation. #Python #OOP #GetterSetter #100DaysOfCode #LearningJourney #Programming
Python OOP: Getters, Setters, and Method Types
More Relevant Posts
-
Understanding Python Class Methods for Efficient Object Creation Class methods in Python are defined using the `@classmethod` decorator and differ from instance methods in significant ways. They receive the class as their first argument (typically called `cls`), instead of the instance (which is `self` for instance methods). This allows class methods to operate on the class itself rather than on instances of the class. In the provided example, we define a simple `Rectangle` class that utilizes a class method to create a square version of it. This is particularly useful when you need to simplify the creation of specific instances without directly invoking the main constructor. When `Rectangle.square(4)` is called, it doesn't create an instance directly; rather, it calls the class method that returns an instance of `Rectangle` with both dimensions set to the specified side length. Class methods become critical when you want to implement factory methods, which provide various means of object creation. This technique centralizes the logic and can include other functionalities, such as validation or default parameters. As a result, your code maintains a clean and organized structure, enhancing readability and maintainability. Quick challenge: How would you modify the `Rectangle` class to include a method that validates that the width and height must be positive? #WhatImReadingToday #Python #PythonProgramming #ClassMethods #OOP #Programming
To view or add a comment, sign in
-
-
🚀 Learning Python the Practical Way: Understanding Virtual Environments Over the past few days, I started learning Python and decided to focus on building instead of just reading syntax. Today, I explored one of the most important concepts for any developer: Virtual Environments (venv) Here’s what I understood: 🔹 A virtual environment is an isolated Python setup for a specific project 🔹 It prevents version conflicts between different projects 🔹 Each project can have its own dependencies without affecting others 💡 Why it matters: While working on multiple projects, different versions of the same library can break things. Virtual environments solve this by keeping everything separate and controlled. 🛠️ What I practiced: Creating a virtual environment Activating and deactivating it Installing packages inside it Understanding how Python uses project-specific paths This concept is very similar to how we manage dependencies in Node.js projects, but implemented differently in Python. Next step: Building a simple backend server using FastAPI to apply this knowledge in real projects. #Python #BackendDevelopment #FastAPI #WebDevelopment #LearningInPublic
To view or add a comment, sign in
-
-
Day 2 – Python Basics+ | Functions, Data Structures, and File I/O** Continuing the beginner Python series with 15 new scripts that build on fundamentals and introduce practical, everyday concepts. **Focus areas for Day 2:** Functions, lists, dictionaries, string methods, control flow, and basic file handling. Each file isolates one concept to support focused learning and easy reference. **Day 2 program list:** | Concept | File | | --- | --- | | Function definition & calls | `01_functions_basic.py` | | Built-in list operations | `02_list_operations.py` | | List comprehensions | `03_list_comprehension.py` | | String methods | `04_string_methods.py` | | Dictionary lookups | `05_dictionary_basics.py` | | Dictionaries as counters | `06_count_characters.py` | | `while` loops + `random` | `07_guessing_game.py` | | Return values | `https://lnkd.in/gFhEe698` | | Sets for deduplication | `09_remove_duplicates.py` | | Math with loops | `10_sum_of_digits.py` | | String slicing | `11_slice_examples.py` | | Sorting & edge cases | `12_find_second_largest.py` | | File read/write | `13_file_write_read.py` | | Anagram checking | `14_check_anagram.py` | | Modules `random` & `string` | `15_simple_password_gen.py` | **How to use:** All scripts use only the Python standard library. Clone the repo, ensure Python 3 is installed, and run any file directly: `python 05_dictionary_basics.py` To run everything at once, reuse the Day 1 runner and update the `PROGRAMS` list with the Day 2 filenames. This set is designed for students, self-learners, and instructors who need clear, modular examples for practice or teaching. Repository link in the first comment. Building this as a multi-day series. If you found Day 1 helpful, Day 2 adds the data structures and file handling that most beginners need next. What topic should Day 3 cover — error handling, OOP basics, or working with APIs? #Python #SoftwareEngineering #LearnToCode #Programming #ComputerScience #DataStructures #SoftwareDevelopment #TechEducation #OpenSource #GitHub #Coding #PythonProgramming Thread Link :- https://lnkd.in/gzzpXUid
To view or add a comment, sign in
-
Python List Methods Tip: append() and extend() Most Python Beginners Don’t Realize This List Mistake, append() and extend() look almost the same… But using the wrong one silently changes your data structure. Here’s the real difference: - append() adds the entire object as ONE element. - extend() adds each element individually. That means this: - append() → Creates nested lists - extend() → Keeps list flat Why This Matters: - This small mistake often causes unexpected bugs while looping, filtering, or processing data. - Many developers only notice it when their logic suddenly stops working. Simple Rule To Remember: - If you want to add one item → append() - If you want to merge items → extend() Small concepts like this make your Python code cleaner and easier to debug. Have you ever accidentally created a nested list using append()? #Python #LearnPython #PythonTips #Programming #Coding #SoftwareEngineering #PythonDeveloper
To view or add a comment, sign in
-
-
📚 Day 30/130 — Python Variables Today in my Python Programming Series, let’s understand one of the most important basics 👇 🔹 What is a Variable? A variable is a container used to store data values in a program. 🔹 Simple Understanding: 👉 Variable = Name that stores a value 🔹 Example: x = 10 name = "Gowthami" 👉 Here, "x" stores a number and "name" stores text 🔹 Rules for Variables: • Must start with a letter or underscore (_) • Cannot start with a number ❌ • No spaces allowed • Case-sensitive (name ≠ Name) 🔹 Types of Values Stored: • Integer → 10 🔢 • String → "Hello" 📝 • Float → 3.14 📊 • Boolean → True/False ✅ 🔹 Why Variables are Important? • Store data for reuse • Make programs dynamic • Improve readability 🔹 Key Idea: 👉 Variables help us store and use data easily in programs 📊See the diagram below for better understanding 📌 Tomorrow’s Topic: 👉 Python Data Types #Python #Programming #Coding #TechLearning #LearningInPublic #Students #Developer #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Python Variables Explained (Beginner Friendly) Today I practiced Python variables and naming conventions 1. Basic Variable Declaration name = "Ankaj" age = 36 salary = 50000 print("Name:", name) print("Age:", age) print("Salary:", salary) 2. Variable Naming Rules user_name = "Ankaj" age1 = 25 _salary = 30000 print(user_name) print(age1) print(_salary) 3. Constants Convention (Uppercase) PI = 3.14 MAX_SPEED = 120 COMPANY_NAME = "ABC Pvt Ltd" print(PI) print(MAX_SPEED) print(COMPANY_NAME) Key Learnings: * Variables store data values * Naming rules matter in clean code * Constants are written in UPPERCASE by convention I’m building my Python skills step by step Follow Ankaj Python Hub for my daily learning journey #Python #Coding #LearnPython #100DaysOfCode #Programming
To view or add a comment, sign in
-
🚀 Python Variables Explained (Beginner Friendly) Today I practiced Python variables and naming conventions 1. Basic Variable Declaration name = "Ankaj" age = 36 salary = 50000 print("Name:", name) print("Age:", age) print("Salary:", salary) 2. Variable Naming Rules user_name = "Ankaj" age1 = 25 _salary = 30000 print(user_name) print(age1) print(_salary) 3. Constants Convention (Uppercase) PI = 3.14 MAX_SPEED = 120 COMPANY_NAME = "ABC Pvt Ltd" print(PI) print(MAX_SPEED) print(COMPANY_NAME) Key Learnings: * Variables store data values * Naming rules matter in clean code * Constants are written in UPPERCASE by convention I’m building my Python skills step by step Follow Ankaj Python Hub for my daily learning journey #Python #Coding #LearnPython #100DaysOfCode #Programming
To view or add a comment, sign in
-
🚀 Project Completed: Expense Tracker using Python I developed a command-line application to track daily expenses using Python and CSV file handling. 🔹 Features: ✔ Add and store expenses ✔ View all transactions ✔ Calculate total spending 🔗 GitHub Repository: https://lnkd.in/gQ4nwR95. This project helped me understand file handling and build a real-world application. #Python #DataScience #BeginnerProject #Learning
To view or add a comment, sign in
-
Modules are one of the most powerful features in Python that help you write clean, reusable, and organized code. * A module is simply a file that contains Python code (functions, variables, or classes) which you can reuse in other programs. * Why use modules? * Code reusability * Better organization * Easy maintenance * Faster development 🔧 Example: # math_module.py def add(a, b): return a + b # main.py import math_module result = math_module.add(5, 3) print(result) * Instead of writing the same logic again and again, modules allow you to write once and use anywhere. * Python also provides built-in modules like: * math * random * datetime #Python #Programming #DataAnalytics #Coding #Learning #PythonBasics
To view or add a comment, sign in
-
Today’s focus was on working with lists and improving problem-solving using Python. I practiced different list operations and real-world scenarios to better understand how data can be handled efficiently. Here’s what I worked on: • Reversing a list • Finding common elements between two lists • Extracting unique elements • Removing duplicates while preserving order • List concatenation and repetition • Removing elements based on index conditions • Inserting elements into a list • List comprehensions (squares, even numbers, word lengths) This session helped me get more comfortable with list manipulation and writing cleaner, more efficient Python code using comprehensions. Step by step, improving logic and coding confidence. Big thanks to VASU KUMAR PALANI and PythonLife for the continuous guidance and support. #Python #CodingJourney #LearnInPublic #PythonLists #Programming #100DaysOfCode #Consistency #TechSkills
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development