Explorer
OOPS_PAPER_PREP.md
OOPS_PAPER_PREP.md
RUN
# ๐ OOPS Paper Preparation Guide (Slides 1-8) Welcome classmates! This guide is created to ensure **no one gets failed** and everyone studies better for our OOPS paper. --- ## ๐ ๏ธ Part 1: Detail-by-Detail Explanations ### 1. Python Lists (Week 2B) - **What is it?** An ordered, mutable collection. Imagine a row of boxes where you can change what is inside. - **Key Features:** - **Ordered:** Items have fixed positions (indices). - **Mutable:** You can change values after creating it. - **Dynamic:** Can grow (append) or shrink (pop). - **Common Methods:** `append()`, `pop()`, `sort()`, `reverse()`. - **Pro Tip:** Use `fruits[-1]` to get the last item instantly! ### 2. Loops & Control (Week 2A) - **For Loop:** Used to go through every item in a list or string. - **While Loop:** Runs as long as a condition is true. - **range(start, stop, step):** Generates numbers. *Remember: It stops one before the 'stop' value!* - **Example:** `for i in range(1, 6):` runs 1, 2, 3, 4, 5. ### 3. Dictionaries & Sets - **Dictionaries:** Key-Value pairs. Like a real dictionary: "Word" (Key) -> "Meaning" (Value). Keys must be unique! - **Sets:** Unordered collection of **unique** elements. No duplicates allowed. Great for clearing duplicates from a list: `list(set(my_list))`. ### 4. User-Defined Functions - **Definition:** Reusable blocks of code. Use `def` to create them. - **Parameters:** Data you pass INTO the function. - **Return:** Data the function sends BACK to you. ### 5. Classes & Objects (OOP) - **Class:** The blueprint (e.g., "Car" design). - **Object:** The actual instance (e.g., your red Toyota). - **State:** Attributes (color, model). - **Behavior:** Methods (drive, brake). ### 6. Instance Modifiers (Security) - **Public:** Access anywhere (`var`). - **Protected:** One underscore (`_var`). Should stay in the family! - **Private:** Two underscores (`__var`). Super secure, use "Name Mangling" (`_Class__var`) to access (not recommended). ### 7. Static Attributes & Methods - **Static Attributes:** Shared by ALL objects of a class (e.g., `company_name`). - **Static Methods:** Utility functions that don't need `self`. Use `@staticmethod`. --- ## ๐ Part 2: OOPS Practice Test (Mock Paper) **Q1: What symbol is used to indicate a private variable in Python?** A) _ B) __ C) # D) * **Q2: Which list method is used to add an item to the end of the list?** A) insert() B) push() C) add() D) append() **Q3: What will be the output of `range(2, 10, 2)`?** A) 2, 4, 6, 8, 10 B) 2, 4, 6, 8 C) 0, 2, 4, 6, 8 D) 2, 4, 6, 10 **Q4: A class is an instance of an object. (True/False)** A) True B) False **Q5: Which modifier is used for "Name Mangling" in Python?** A) Public B) Protected C) Private D) Static --- ## ๐ Answers (Check after trying!) 1. B (Private uses __) 2. D (append adds to the end) 3. B (Stops before 10) 4. B (Object is an instance of a Class!)