<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Krishna Chaitanya on Medium]]></title>
        <description><![CDATA[Stories by Krishna Chaitanya on Medium]]></description>
        <link>https://medium.com/@chaitanya4a3?source=rss-534f3edae7ca------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*2AgTI7Sqzsw7ALvP</url>
            <title>Stories by Krishna Chaitanya on Medium</title>
            <link>https://medium.com/@chaitanya4a3?source=rss-534f3edae7ca------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 08:03:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chaitanya4a3/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Python Django Project Setup]]></title>
            <link>https://medium.com/@chaitanya4a3/python-django-project-setup-098516798d22?source=rss-534f3edae7ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/098516798d22</guid>
            <category><![CDATA[django-installation]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-project-ideas]]></category>
            <dc:creator><![CDATA[Krishna Chaitanya]]></dc:creator>
            <pubDate>Sun, 06 Jul 2025 14:54:55 GMT</pubDate>
            <atom:updated>2025-07-06T15:17:05.928Z</atom:updated>
            <content:encoded><![CDATA[<h4>Django Project Setup — Step by Step Guide</h4><h4>Step 1: Install Python (if not installed)</h4><p>Check Python version:<br> python — version<br> If not installed, download from <a href="https://www.python.org/downloads/">https://www.python.org/downloads/</a> and ensure ‘Add Python to PATH’ is selected.</p><h4>Step 2: Create and Activate a Virtual Environment</h4><p>Open Command prompt and do fallowing.</p><p>Create a folder:<br> mkdir my_django_project<br> cd my_django_project<br> <br> Create virtual environment:<br> Windows: python -m venv env<br> macOS/Linux: python3 -m venv env<br> <br> Activate virtual environment:<br> Windows: env\Scripts\activate<br> macOS/Linux: source env/bin/activate</p><h4>Step 3: Install Django</h4><p>pip install django<br> Check Django version:<br> django-admin — version</p><h4>Step 4: Create a New Django Project</h4><p>django-admin startproject mysite .</p><h4>Step 5: Run the Development Server</h4><p>cd mysite</p><p>python manage.py runserver<br> Visit: <a href="http://127.0.0.1:8000/">http://127.0.0.1:8000</a></p><h4>Step 6: Create a Django App</h4><p>python manage.py startapp myapp</p><h4>Step 7: Register the App</h4><p>Open mysite/settings.py and add ‘myapp’ to INSTALLED_APPS.</p><h4>Step 8: Define Models</h4><p>In myapp/models.py:<br> from django.db import models<br> <br> class Book(models.Model):<br> title = models.CharField(max_length=100)<br> author = models.CharField(max_length=50)</p><h4>Step 9: Make Migrations and Migrate</h4><p>python manage.py makemigrations<br> python manage.py migrate</p><h4>Step 10: Create a Superuser</h4><p>python manage.py createsuperuser</p><h4>Step 11: Run the Server Again</h4><p>python manage.py runserver<br> Visit: <a href="http://127.0.0.1:8000/admin">http://127.0.0.1:8000/admin</a></p><h4>Step 12: Add Views and URLs</h4><p>In myapp/views.py:<br> from django.http import HttpResponse<br> <br> def home(request):<br> return HttpResponse(‘Hello, Django!’)<br> <br> Create myapp/urls.py:<br> from django.urls import path<br> from . import views<br> <br> urlpatterns = [<br> path(‘’, views.home, name=’home’),<br> ]<br> <br> In mysite/urls.py:<br> from django.urls import path, include<br> <br> urlpatterns = [<br> path(‘admin/’, admin.site.urls),<br> path(‘’, include(‘myapp.urls’)),<br> ]</p><h4>Step 13: Optional — Requirements File</h4><p>pip freeze &gt; requirements.txt<br> pip install -r requirements.txt</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=098516798d22" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python OOPs Principles]]></title>
            <link>https://medium.com/@chaitanya4a3/python-oops-principles-7c3f7f899b00?source=rss-534f3edae7ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c3f7f899b00</guid>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[oops-concepts]]></category>
            <category><![CDATA[python-oops-concept]]></category>
            <category><![CDATA[objects]]></category>
            <category><![CDATA[oops-interview-questions]]></category>
            <dc:creator><![CDATA[Krishna Chaitanya]]></dc:creator>
            <pubDate>Thu, 03 Jul 2025 16:30:31 GMT</pubDate>
            <atom:updated>2025-07-03T16:36:45.011Z</atom:updated>
            <content:encoded><![CDATA[<p>OOP principles help make your code more <strong>organized</strong>, <strong>reusable</strong>, and <strong>scalable</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*6E_0n3BGBaFG56MdNDM8eA.png" /></figure><p>Let’s explore Python OOP (Object-Oriented Programming) principles using a fun example of a Zoo! 🦁🐒🐍</p><h4>1. Encapsulation — “The Zookeeper’s Keychain 🔐”</h4><p>Encapsulation means wrapping data (attributes) and methods (functions) into a single unit (class).</p><p>You protect the inner workings, just like a zookeeper keeps animal details locked up!</p><p><strong>Example</strong>:</p><p>class Animal:<br> def __init__(self, name, species):<br> self.__name = name # private<br> self.__species = species # private<br> <br> def get_info(self):<br> return f”{self.__name} is a {self.__species}”<br> <br> leo = Animal(“Leo”, “Lion”)<br> print(leo.get_info()) # Leo is a Lion</p><p>🔍 Analogy: Visitors can’t walk into the lion’s den — they ask the zookeeper (a method) for info.</p><h4>2. Abstraction — “Don’t Feed the Animals 🪧”</h4><p>Abstraction means hiding complex stuff and showing only what’s necessary. Like how the zoo doesn’t show how they clean the elephant’s enclosure — just the elephant!</p><p><strong>Example</strong>:</p><p>from abc import ABC, abstractmethod<br> <br> class Animal(ABC):<br> @abstractmethod<br> def make_sound(self):<br> pass<br> <br> class Monkey(Animal):<br> def make_sound(self):<br> return “Ooh ooh aah aah!”<br> <br> monkey = Monkey()<br> print(monkey.make_sound()) # Ooh ooh aah aah!</p><p>🔍 Analogy: You don’t know how the monkey thinks, you just see it go “Ooh ooh!”</p><h4>3. Inheritance — “Family Tree of the Jungle 🌳”</h4><p>Inheritance means letting child classes inherit features from parent classes.</p><p><strong>Example</strong>:</p><p>class Animal:<br> def __init__(self, name):<br> self.name = name<br> <br> def eat(self):<br> return f”{self.name} is eating.”<br> <br> class Tiger(Animal):<br> def roar(self):<br> return f”{self.name} roars loudly!”<br> <br> tiggy = Tiger(“Tiggy”)<br> print(tiggy.eat()) # Tiggy is eating.<br> print(tiggy.roar()) # Tiggy roars loudly!</p><p>🔍 Analogy: Tigers are animals, so they inherit animal behaviors like eating — and add their own like roaring.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*0zTS_UmsfViSZUaBuuFoMA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*2eTTynMFAIa3DhYvm2TgWQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*gg5VrnP0KGtUtjMKRrWEiQ.png" /></figure><h4>2. Multiple Inheritance</h4><p><strong>Definition:</strong> One class inherits from more than one parent class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*hCm3y0V1m8E4UyiG05-XzA.png" /></figure><h4>3. Multilevel Inheritance</h4><p><strong>Definition:</strong> A class inherits from a class which itself inherits from another class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*S2MPSOgJkug-nupmd0YvDQ.png" /></figure><h4>4. Hierarchical Inheritance</h4><p><strong>Definition:</strong> Multiple child classes inherit from a single parent class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*qMC5w8-ZgjGPoQiCNDjY4Q.png" /></figure><h4>4. Polymorphism — “Same Show, Different Stars 🎭”</h4><p>Polymorphism means different classes can have methods with the same name, but different behavior.</p><p><strong>Example</strong>:</p><p>class Parrot:<br> def speak(self):<br> return “Squawk!”<br> <br> class Snake:<br> def speak(self):<br> return “Hissss!”<br> <br> def animal_sound(animal):<br> print(animal.speak())<br> <br> animal_sound(Parrot()) # Squawk!<br> animal_sound(Snake()) # Hissss!</p><p>🔍 Analogy: All animals speak… just in their own unique way.</p><p><strong>super(): </strong>super is a base class constructor.</p><ul><li>super() allows the child class to <strong>reuse</strong> the code from the parent class.</li><li>Avoids duplicating code from the base class (e.g., setting name).</li><li>Makes your code <strong>cleaner</strong>, especially with <strong>multiple inheritance</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*tDQlwWSeuGOKsj6xt8bJUw.png" /></figure><h4>Summary 🧁</h4><p>• Encapsulation: 📦 “Hide the treats inside the box”</p><p>• Abstraction: 🎭 “See the magic, not the trick”</p><p>• Inheritance: 👨‍👩‍👧‍👦 “Traits passed down the animal family”</p><ul><li>Polymorphism: 🗣️ “Different voices, one command”</li></ul><p><strong>OOPs Principles Interview Questions:</strong></p><ul><li>What are the four main principles of OOP? Explain each with an example.</li><li>What is the difference between abstraction and encapsulation?</li><li>How does Python implement inheritance? Can you explain with an example?</li><li>What is polymorphism? Explain method overriding and method overloading in Python.</li><li>How does encapsulation help in code security and maintenance?</li><li>What is the role of constructors in OOP? How is __init__() used in Python?</li><li>Can a class inherit from multiple classes in Python? What is the method resolution order (MRO)?</li><li>What is the difference between a class and an object? Give real-life examples.</li><li>Explain hierarchical and hybrid inheritance with an example.</li><li>What is an abstract class in Python? How does it enforce abstraction?</li></ul><p><strong>Practice Questions:</strong></p><ol><li><strong>Design a class hierarchy for a Library System.</strong></li></ol><ul><li>Base class: Item (with title, author, ID)</li><li>Subclasses: Book, Magazine, DVD</li><li>Implement methods like check_out() and return_item()</li><li>Use inheritance and polymorphism.</li></ul><p><strong>2. Create a Billing System for an Online Store.</strong></p><ul><li>Class Product: name, price</li><li>Class Cart: list of products, add/remove item, calculate total</li><li>Apply encapsulation for price calculation logic.</li></ul><p><strong>3. Build a Vehicle Inheritance Model.</strong></p><ul><li>Base class: Vehicle</li><li>Subclasses: Car, Bike, Truck</li><li>Each subclass should override a method move() with its own behavior.</li></ul><p><strong>4. Implement a simple ATM System using OOP.</strong></p><ul><li>Class: Account (balance, pin)</li><li>Methods: check_balance(), withdraw(), deposit()</li><li>Use encapsulation to protect sensitive data.</li></ul><p><strong>5. Design a Student Management System.</strong></p><ul><li>Class Person with attributes: name, age</li><li>Class Student inherits from Person and adds: student_id, courses</li><li>Add method to display full student details using abstraction.</li></ul><p><strong>6. Create an Animal Sound Simulation.</strong></p><ul><li>Use polymorphism: each animal class (Dog, Cat, Cow) should implement make_sound()</li><li>Write a function play_sound(animal) that works for all.</li></ul><p><strong>7. Build a Company Employee Hierarchy.</strong></p><ul><li>Class Employee with salary, name</li><li>Subclasses: Manager, Developer, Intern</li><li>Add bonus logic using method overriding.</li></ul><p><strong>8. Develop a Movie Ticket Booking System.</strong></p><ul><li>Class Movie (name, seats, time)</li><li>Class Ticket to book or cancel tickets</li><li>Use encapsulation for seat management and price.</li></ul><p><strong>9. Create a Shape Drawing App using Abstraction.</strong></p><ul><li>Abstract class: Shape</li><li>Subclasses: Circle, Rectangle, Triangle with method draw()</li><li>Call them in a loop to simulate drawing.</li></ul><p><strong>10. Design a Food Delivery App Backend Classes.</strong></p><ul><li>Class Restaurant with menu</li><li>Class Order with cart, delivery address</li><li>Use multiple inheritance for Customer and DeliveryAgent</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c3f7f899b00" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Object-Oriented Programming (OOP) in Python]]></title>
            <link>https://medium.com/@chaitanya4a3/object-oriented-programming-oop-in-python-562a74c630f9?source=rss-534f3edae7ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/562a74c630f9</guid>
            <category><![CDATA[python-oops-concept]]></category>
            <category><![CDATA[oops-concepts]]></category>
            <category><![CDATA[oop-python]]></category>
            <category><![CDATA[variable-scope-in-python]]></category>
            <category><![CDATA[oops-interview-questions]]></category>
            <dc:creator><![CDATA[Krishna Chaitanya]]></dc:creator>
            <pubDate>Tue, 01 Jul 2025 17:08:30 GMT</pubDate>
            <atom:updated>2025-07-01T17:08:30.760Z</atom:updated>
            <content:encoded><![CDATA[<h4>What is OOPs?</h4><p>Object-Oriented Programming (OOP) is a programming paradigm based on the concept of objects. These objects can contain data, in the form of fields (attributes), and code, in the form of procedures (methods).</p><h4>Definition</h4><p>OOP is a method of programming that organizes code into objects that encapsulate both data and behavior.</p><h4>Advantages of OOPs</h4><p>1. Modularity — Code is organized into independent classes.<br> 2. Reusability — Classes can be reused across programs.<br> 3. Encapsulation — Hides internal object details from the outside.<br> 4. Abstraction — Exposes only essential features.<br> 5. Inheritance — Allows new classes to inherit from existing ones.<br> 6. Polymorphism — Allows methods to behave differently based on context.<br> 7. Maintainability — Easier to update and debug code.</p><h4>Class:</h4><p>A class is a blueprint for creating objects. It defines attributes and methods.</p><h4>Syntax of Class:</h4><p>class ClassName:<br> def __init__(self, value):<br> self.value = value<br> <br> def show(self):<br> print(“Value:”, self.value)</p><p><strong>Self: </strong>self is a reference to the <strong>current object</strong>. It is used inside a class method to access instance variables and other methods of the class.&quot;</p><h4>Object</h4><p>An object is an instance of a class. It is used to access the class methods and attributes.</p><h4>Syntax of Creating Object and Calling Class</h4><p>obj = ClassName(10) # Creating an object<br> obj.show() # Calling method using the object</p><h4>Class vs Object:</h4><p>Class:<br> — Blueprint or template<br> — Does not occupy memory<br> — Used to define properties<br> — Example: class Car:<br> <br> Object:<br> — Instance of the class<br> — Occupies memory<br> — Used to access properties<br> — Example: my_car = Car()</p><h4>What is a Constructor?</h4><p>A constructor is a special method that is automatically called when an object is created. In Python, the constructor method is __init__().</p><h4>Types of Constructors in Python</h4><ol><li>Default Constructor: No parameters</li><li>Parameterized Constructor: Accepts parameters</li></ol><p>Note: Python does not support multiple constructors directly, but method overloading can be used.</p><h4>Example: Default Constructor</h4><p>class Demo:<br> def __init__(self):<br> print(“Default Constructor”)<br> <br> obj = Demo()</p><h4>Example: Parameterized Constructor</h4><p>class Person:<br> def __init__(self, name, age):<br> self.name = name<br> self.age = age<br> <br> def show(self):<br> print(f”Name: {self.name}, Age: {self.age}”)<br> <br> p1 = Person(“Krishna”, 30)<br> p1.show()</p><h4>Python Variable Scope</h4><p>In Python, scope refers to the region of a program where a variable is recognized and can be accessed. Depending on where a variable is declared, it can have different levels of visibility and lifetime.</p><h4>What is Scope in Python?</h4><p>Scope defines the accessibility of a variable — where it can be used in your code. It ensures that variables do not conflict with one another and are only accessible where needed.</p><h4>Types of Scopes in Python</h4><p>Python uses the LEGB Rule to resolve variable names. This rule refers to four types of scopes:</p><p>1. Local — Names declared inside a function. Only accessible within that function.</p><p>2. Enclosing — Names in the local scope of enclosing functions (for nested functions).</p><p>3. Global — Names assigned at the top-level of a script or module. Accessible throughout the module.</p><p>4. Built-in — Names preassigned in Python (e.g., len(), print()).</p><h4>1. Local Scope</h4><p>A variable declared inside a function belongs to the local scope.</p><p>def my_function():<br> x = 10 # Local variable<br> print(“Local x:”, x)<br> <br> my_function()<br> # print(x) # Error: x is not accessible here</p><h4>2. Enclosing Scope (Nonlocal)</h4><p>A variable declared in the outer function of a nested function is in the enclosing scope.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*6qm-Vum7w2rUmF9qetM2Hw.png" /></figure><h4>3. Global Scope</h4><p>A variable declared outside all functions is global and can be accessed anywhere in the module.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*_h-vH1JZ08ocqTrAhJSAqA.png" /></figure><p>To modify a global variable inside a function, use the global keyword:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*VyqPGFx3SFXzuuom9nj2BA.png" /></figure><h4>4. Built-in Scope</h4><p>These are names that Python reserves internally, available without importing or defining.</p><p>print(len(“Hello”)) # len is a built-in function</p><p>You can view built-in names using:</p><p>print(dir(__builtins__))</p><h4>LEGB Rule Summary</h4><p>When you access a variable, Python searches in the following order:</p><p>1. Local — current function.</p><p>2. Enclosing — outer/nested functions.</p><p>3. Global — top-level of the module.</p><p>4. Built-in — pre-defined in Python.</p><h4>Example:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*7ok-JzVkNnhJ5qg_N6uFMg.png" /></figure><blockquote><strong>Interview Questions</strong></blockquote><ol><li>What is Object-Oriented Programming (OOP)?</li><li>What is the difference between a class and an object in Python? (Define a class and explain how an object is created from it.)</li><li>What is a constructor in Python? How is it defined and when is it called? (Discuss the __init__() method with an example.)</li><li>What is the difference between instance variables and class variables? Give examples.</li><li>How is self used in a class? Why is it necessary in method definitions?</li><li>What are the different types of variable scopes in Python? Explain the LEGB rule?</li><li>How do global and nonlocal keywords affect variable scope inside nested functions? Provide an example.</li></ol><blockquote><strong><em>Practice Tasks:</em></strong></blockquote><p>1. Write a Python class named Employee with instance variables name and salary. Add a constructor to initialize them and a method display() to print details.</p><p>2. What will be the output of the following code?</p><p>class Test:<br> def __init__(self, x):<br> self.x = x<br> <br> a = Test(10)<br> b = Test(20)<br> print(a.x)<br> print(b.x)</p><p>3. Explain the role of self in a Python class. Can a method work without it? Give an example.</p><p>4. Write a class Circle with a class variable pi = 3.14 and an instance variable radius. Add a method to calculate area.</p><p>5. Differentiate between instance method, class method, and static method. Create a class that uses all three.</p><p>6. What is the output of the following code?</p><p>x = 5<br> <br> def outer():<br> x = 10<br> def inner():<br> x = 15<br> print(“Inner:”, x)<br> inner()<br> print(“Outer:”, x)<br> <br> outer()<br> print(“Global:”, x)</p><p>7. What will the output be? Explain why.</p><p>x = 100<br> <br> def modify():<br> global x<br> x = x + 50<br> <br> modify()<br> print(x)</p><p>8. Create a nested function where a variable in the outer function is modified by the inner function using nonlocal.</p><p>9. What does the dir(__builtins__) function return?</p><p>10. Identify the scope of each x in the following code and explain the output.</p><p>x = “global”<br> <br> def func1():<br> x = “enclosing”<br> def func2():<br> x = “local”<br> print(“func2:”, x)<br> func2()<br> print(“func1:”, x)<br> <br> func1()<br> print(“global:”, x)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=562a74c630f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Module]]></title>
            <link>https://medium.com/@chaitanya4a3/python-module-dea270ed2ab1?source=rss-534f3edae7ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/dea270ed2ab1</guid>
            <category><![CDATA[python-imports]]></category>
            <category><![CDATA[python-practice-question]]></category>
            <category><![CDATA[python-interview-question]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-module]]></category>
            <dc:creator><![CDATA[Krishna Chaitanya]]></dc:creator>
            <pubDate>Tue, 01 Jul 2025 16:21:37 GMT</pubDate>
            <atom:updated>2025-07-01T16:24:24.805Z</atom:updated>
            <content:encoded><![CDATA[<h4>Python Module:</h4><p>A module in Python is simply a file containing Python code (with a .py extension). It can include variables, functions, classes, or runnable code.</p><p><strong>Why do we use Modules?</strong></p><p>1. Reusability — Write once, use multiple times.</p><p>2. Organization — Break large programs into smaller manageable pieces.</p><p>3. Maintainability — Easier to update parts of your program.</p><p>4. Namespace Separation — Avoids conflicts between function/variable names.</p><p>5. Built-in Functions — Access powerful functionality via built-in libraries (e.g., math, random).</p><h4>Types of Modules:</h4><p>1. Built-in Modules — Pre-installed in Python (e.g., math, random).</p><p>2. User-defined Modules — Created by the user (e.g., mymodule.py).</p><p>3. Third-party Modules — Installed using pip (e.g., numpy, pandas).</p><h4>Predefined (Built-in) Modules</h4><p>Python comes with many ready-to-use modules. Examples below:</p><h4>Examples of Built-in Modules</h4><h4>math Module</h4><p>import math<br> print(math.sqrt(16)) # 4.0<br> print(math.pi) # 3.141592653589793</p><h4>random Module</h4><p>import random<br> print(random.randint(1, 10)) # Random integer between 1 and 10</p><h4>datetime Module</h4><p>import datetime<br> now = datetime.datetime.now()<br> print(“Current date and time:”, now)</p><h4>os Module</h4><p>import os<br> print(“Current directory:”, os.getcwd())</p><h4>User-defined Modules</h4><p>Step 1: Create a module (file):</p><p># mymodule.py<br> def greet(name):<br> return f”Hello, {name}!”<br> <br> def add(a, b):<br> return a + b</p><p>Step 2: Import and use the module:</p><p># main.py<br> import mymodule<br> <br> print(mymodule.greet(“Krishna”)) # Hello, Krishna!<br> print(mymodule.add(5, 3)) # 8</p><p>Alternative import style:</p><p>from mymodule import greet, add<br> <br> print(greet(“Moni”)) # Hello, Moni!<br> print(add(2, 4)) # 6</p><h4>Example: Combining Everything</h4><p>math_tools.py</p><p>PI = 3.14159<br> <br> def area_circle(radius):<br> return PI * radius * radius<br> <br> def perimeter_circle(radius):<br> return 2 * PI * radius</p><p>app.py</p><p>import math_tools<br> <br> print(math_tools.area_circle(5)) # 78.53975<br> print(math_tools.perimeter_circle(5)) # 31.4159</p><h4>Best Practices</h4><p>— Use descriptive names for your modules.<br> — Group related functions and classes together.<br> — Avoid naming conflicts with built-in modules.<br> — Use __name__ == “__main__” to run tests only when the file is run directly.</p><h4>Python Module Interview Questions</h4><ol><li><strong>What is a module in Python? How is it different from a script?</strong><br> → Explain the concept of a .py file used for reuse vs. a script that is typically executed directly.</li><li><strong>What are the advantages of using modules in Python?</strong><br> → Discuss reusability, organization, namespace separation, and modular programming.</li><li><strong>Explain the difference between built-in, user-defined, and third-party modules.</strong><br> → Clarify their origin, usage, and how they are imported.</li><li><strong>How do you create and use a user-defined module in Python?</strong><br> → Give a real-world example of defining functions in one .py file and using them in another.</li><li><strong>What is the use of </strong><strong>__name__ == &quot;__main__&quot; in modules?</strong><br> → Explain how this helps run test code only when the file is executed directly.</li><li><strong>How can you reload a module without restarting the Python interpreter?</strong><br> → Answer with importlib.reload(module_name).</li><li><strong>What is the difference between </strong><strong>import module, </strong><strong>from module import name, and </strong><strong>from module import *?</strong><br> → Highlight namespace management, readability, and risks of wildcard imports.</li><li><strong>How can you access a module that is located in another directory?</strong><br> → Mention sys.path.append(&#39;path&#39;) or use of packages and relative imports.</li><li><strong>What are some common built-in modules in Python and their uses?</strong><br> → Example: math, datetime, os, random, json.</li><li><strong>How do you install and use third-party modules in Python?</strong><br> → Show command pip install &lt;module&gt; and how to import after installation.</li></ol><h4>Practice Tasks for Python Modules</h4><h4>Task 1: Create and Use a Simple Module</h4><ul><li>Create a module calc.py with functions add, subtract, multiply, and divide</li><li>Import it into another script and perform all operations.</li></ul><h4>Task 2: Build a Geometry Toolkit</h4><ul><li>Create a file geometry.py with functions to calculate:</li><li>Area and perimeter of a circle</li><li>Area and perimeter of a rectangle</li><li>Use it in a separate file to display the results for given inputs.</li></ul><h4>Task 3: Use Built-in Modules</h4><ul><li>Use the following modules:</li><li>math – to find square roots and factorials.</li><li>random – to generate random passwords.</li><li>datetime – to calculate age from date of birth.</li></ul><h4>Task 4: Directory Analyzer</h4><ul><li>Use the os module to:</li><li>List all files in a directory</li><li>Count how many .py files are present</li><li>Create a new folder named backup</li></ul><h4>Task 5: Reload Module During Development</h4><ul><li>Create a module temp.py with a simple function.</li><li>Import and use it in another script.</li><li>Change the function in temp.py, then reload the module using importlib.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dea270ed2ab1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python File Handling]]></title>
            <link>https://medium.com/@chaitanya4a3/python-file-handling-35ac57806f16?source=rss-534f3edae7ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/35ac57806f16</guid>
            <category><![CDATA[python-interview-question]]></category>
            <category><![CDATA[python-file-handling]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-practical]]></category>
            <category><![CDATA[file-handling]]></category>
            <dc:creator><![CDATA[Krishna Chaitanya]]></dc:creator>
            <pubDate>Mon, 30 Jun 2025 17:41:57 GMT</pubDate>
            <atom:updated>2025-06-30T17:41:57.009Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Python file handling</strong> refers to the process of <strong>creating, opening, reading, writing, appending, and deleting files</strong> using built-in Python functions and methods.</p><p>It allows programs to <strong>interact with external files</strong> (like .txt, .csv, .json, etc.) stored on your system — for tasks such as:</p><ul><li>Saving user data</li><li>Logging application events</li><li>Loading configuration or data files</li><li>Exporting reports</li></ul><p><strong>Why is File Handling Important?</strong></p><ul><li>Helps <strong>store and retrieve data</strong> permanently.</li><li>Used in <strong>data processing</strong>, <strong>report generation</strong>, <strong>log tracking</strong>, and more.</li><li>Makes applications more dynamic and useful.</li></ul><p><strong>Key Functions in Python File Handling:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*STaDDae7W0Qa3y9wOMUt9A.png" /></figure><p><strong>open — </strong>open() function to open a file in a specific mode.</p><p>file = open(“filename.txt”, “mode”)<br># Perform operations<br>file.close()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*kT-_qrL0LtOtmHh09OMYcg.png" /></figure><p><strong>Create File:</strong></p><p>Creating a new file using mode &#39;x&#39; (exclusive creation) or &#39;w&#39; (write).</p><p>file = open(“myfile.txt”, “x”) # or “w”<br>file.close()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*x0conBKT195oQmV4jQk7_Q.png" /></figure><p><strong>Read File: </strong>Reading content from an existing file using mode &#39;r&#39;.</p><p>file = open(“myfile.txt”, “r”)<br>data = file.read()<br>file.close()</p><p>file = open(“sample.txt”, “r”)<br>print(“File Content:”)<br>print(file.read())<br>file.close()</p><p>Other reading methods:</p><ul><li>file.readline() – reads one line</li><li>file.readlines() – returns list of lines</li></ul><p><strong>Write File: </strong>Write new data to a file using mode &#39;w&#39;. Overwrites existing content.</p><p><strong>Syntax</strong>:</p><p>file = open(“myfile.txt”, “w”)<br>file.write(“Hello World!”)<br>file.close()</p><p><strong>Example:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*LZs5_egkj0N9zWCi9qqJDw.png" /></figure><p><strong>Append File: </strong>Adds content to the end of an existing file using mode &#39;a&#39;.</p><p><strong>Syntax:</strong></p><p>file = open(“myfile.txt”, “a”)<br>file.write(“New data”)<br>file.close()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*_RVZjZutekX4ENikHSljmQ.png" /></figure><p><strong>Delete a File: </strong>Deletes a file using the os module.</p><p>Syntax:</p><p>import os<br>os.remove(“filename.txt”)</p><p>Example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*v2Oe4quDmSY-sEzle88Lsw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*exM4nfYbTpI0hlpSqf9UYg.png" /></figure><blockquote><strong><em>Interview Questions on Python File Handling</em></strong></blockquote><ol><li><strong>What is file handling in Python and why is it important?</strong><br> <em>(Explains the concept and practical usage in real-world applications.)</em></li><li><strong>Explain the </strong><strong>open() function in Python. What are its parameters?</strong><br> <em>(Talk about </em><em>filename, </em><em>mode, and optional encoding.)</em></li><li><strong>What are the different modes available to open a file in Python? Explain each.</strong><br> <em>(‘r’, ‘w’, ‘a’, ‘x’, ‘rb’, ‘wb’, etc.)</em></li><li><strong>What is the difference between </strong><strong>read(), </strong><strong>readline(), and </strong><strong>readlines()?</strong><br> <em>(Used for reading whole file, single line, or list of lines.)</em></li><li><strong>How do you write data to a file in Python? What happens if the file already exists?</strong><br> <em>(Use of </em><em>write() and what </em><em>&#39;w&#39; mode does.)</em></li><li><strong>What is the purpose of the </strong><strong>with statement when working with files?</strong><br> <em>(Automatic file closing and resource management.)</em></li><li><strong>How do you append data to an existing file without overwriting it?</strong><br> <em>(Using </em><em>&#39;a&#39; mode and </em><em>write().)</em></li><li><strong>How do you check if a file exists before reading or deleting it?</strong><br> <em>(Using </em><em>os.path.exists() or </em><em>os module.)</em></li><li><strong>How do you delete a file in Python? What if the file doesn’t exist?</strong><br> <em>(Using </em><em>os.remove() with error handling.)</em></li><li><strong>What is the difference between text mode and binary mode in file handling?</strong><br> <em>(Text = </em><em>&#39;t&#39;, Binary = </em><em>&#39;b&#39;; and use cases like images, audio, etc.)</em></li></ol><blockquote><strong><em>Tasks for Practice:</em></strong></blockquote><p><strong>1. Log Writer App</strong></p><p><strong>Task:</strong> Create a program that logs user activities (like login, logout) to a file.</p><ul><li>Use append mode to add logs with timestamps.</li><li>Ex: [2025–06–30 10:00:00] User logged in</li></ul><p><strong>2. Read and Display File Contents</strong></p><p><strong>Task:</strong> Read a .txt file and display each line with line numbers.</p><ul><li>Handle file not found error.</li></ul><p><strong>3. To-Do List Manager</strong></p><p><strong>Task:</strong> Create a to-do list app that:</p><ul><li>Adds tasks to a file (write or append)</li><li>Reads all tasks from the file</li><li>Deletes all tasks (clear file content using &#39;w&#39; mode)</li></ul><p><strong>4. User Feedback Collector</strong></p><p><strong>Task:</strong> Accept user input and store it in a file.</p><ul><li>Every time a new feedback is entered, it should be appended.</li></ul><h4><strong>5. Search in File</strong></h4><p><strong>Task:</strong> Search for a specific keyword in a file and print how many times it appears.</p><ul><li>Bonus: Show the lines where it occurs.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35ac57806f16" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Exception Handling]]></title>
            <link>https://medium.com/@chaitanya4a3/python-exception-handling-533fc222e31b?source=rss-534f3edae7ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/533fc222e31b</guid>
            <category><![CDATA[python-interview-question]]></category>
            <category><![CDATA[python-task]]></category>
            <category><![CDATA[python-exception]]></category>
            <category><![CDATA[python-try-except]]></category>
            <category><![CDATA[python-error]]></category>
            <dc:creator><![CDATA[Krishna Chaitanya]]></dc:creator>
            <pubDate>Sat, 28 Jun 2025 07:09:39 GMT</pubDate>
            <atom:updated>2025-06-28T07:09:39.885Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Table of Contents:</strong></p><ul><li>Python Exception Handling — Definition and Example</li><li>Why We Need to Use Exception Handling</li><li>Advantages of Exception Handling</li><li>What is Error Handling and Example</li><li>Difference Between Exception and Error</li><li>try, except, else, and finally Blocks</li><li>Common Exceptions in Python with Example and Use Case</li><li>Python Catching Exceptions</li><li>Catching Specific Exceptions</li><li>Catching Multiple Exceptions</li><li>Raise an Exception</li></ul><h4>1. Python Exception Handling — Definition and Example</h4><p>Exception handling in Python is a mechanism to handle runtime errors, allowing the program to continue running instead of crashing.<br> <br> <strong>Example</strong>:<br> try:<br> result = 10 / 0<br> except ZeroDivisionError:<br> print(“You can’t divide by zero!”)</p><h4>2. Why We Need to Use Exception Handling</h4><p>— To avoid program crashes.<br> — To handle unexpected situations gracefully.<br> — To log and debug errors.<br> — To provide user-friendly error messages.<br> <br> <strong>Without exception handling:</strong><br> a = 10 / 0 # Program crashes<br> <br> <strong>With exception handling:</strong><br> try:<br> a = 10 / 0<br> except ZeroDivisionError:<br> print(“Handled the error, so program won’t crash.”)</p><h4>3. Advantages of Exception Handling</h4><ul><li>Prevents program crashes.</li><li>Organizes error-handling logic.</li><li>Ensures resource cleanup.</li><li>Provides meaningful messages to users.</li><li>Code clarity</li><li>Debugging support</li><li>Resource cleanup (using finally block)</li></ul><h4>4. What is Error Handling and Example</h4><p>Error handling is the process of anticipating, detecting, and resolving programming errors.<br> <br> <strong>Example</strong>:<br> try:<br> f = open(“file.txt”, “r”)<br> except FileNotFoundError:<br> print(“File not found!”)</p><h4>5. Difference Between Exception and Error</h4><p><strong>Exception</strong>:<br> — Events that occur during execution<br> — Can be handled using try-except<br> — Example: ZeroDivisionError, ValueError<br> <br> <strong>Error</strong>:<br> — Serious problems outside control<br> — Rarely handled in code<br> — Example: MemoryError, RecursionError</p><h4>6. try, except, else, finally Blocks</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*CZL840zibW7QZBfnDB6jqw.png" /></figure><p>try:<br> num = int(input(“Enter a number: “))<br> except ValueError:<br> print(“That’s not a valid number!”)<br> else:<br> print(“Success! You entered:”, num)<br> finally:<br> print(“Execution finished.”)</p><h4>7. Common Exceptions in Python with Example &amp; Use Case</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*121n5FtSno0BDnjjjlm5_w.png" /></figure><h4>8. Python Catching Exceptions</h4><p>try:<br> x = int(“abc”)<br> except Exception as e:<br> print(“Exception caught:”, e)</p><h4>9. Catching Specific Exceptions</h4><p>try:<br> result = 10 / int(input(“Enter a number: “))<br> except ValueError:<br> print(“Input must be a number.”)<br> except ZeroDivisionError:<br> print(“You can’t divide by zero.”)</p><h4>10. Catching Multiple Exceptions</h4><p>try:<br> a = int(“abc”)<br> b = 10 / 0<br> except (ValueError, ZeroDivisionError) as e:<br> print(“Caught error:”, e)</p><h4>11. Raise an Exception</h4><p>age = -1<br> if age &lt; 0:<br> raise ValueError(“Age can’t be negative”)</p><blockquote><strong><em>Interview Questions on Exception Handling</em>:</strong></blockquote><ol><li>What is exception handling in Python?</li><li>Why is exception handling important in Python programs?</li><li>What is the difference between an error and an exception?</li><li>What are the key blocks used in exception handling in Python?</li><li>What is the use of the else block in a try-except-else-finally structure?</li><li>What is the role of the finally block? Will it execute even if there&#39;s an exception?</li><li>Can we have multiple except blocks? Give an example.</li><li>Can you catch multiple exceptions in a single except block? How?</li><li>How do you raise a custom exception in Python?</li><li>What is the base class for all exceptions in Python?</li></ol><blockquote><strong><em>Tasks for Practice:</em></strong></blockquote><p>1<strong>. User Input Validation System</strong></p><p>Build a script that takes user inputs (name, age, email).<br> — Handle empty input<br> — Raise ValueError for invalid age (&lt;0)<br> — Raise custom exception for invalid email (no ‘@’)</p><p>2. <strong>File Reader Tool</strong></p><p>Build a function that opens a file and reads its content.<br> — Handle FileNotFoundError if the file doesn’t exist<br> — Handle PermissionError for restricted files<br> — Use finally to always close the file</p><p>3. <strong>Safe Division Function</strong></p><p>Write a safe_divide(a, b) function that:<br> — Catches ZeroDivisionError<br> — Catches TypeError if a or b are not numbers<br> — Logs errors and returns meaningful messages</p><p>4. <strong>API Request Handler (Mock Project)</strong></p><p>Simulate an API call using a function.<br> — Raise exception for invalid endpoint<br> — Handle timeout with a custom TimeoutError<br> — Use try-except-finally to manage connection lifecycle</p><p>5. <strong>Dictionary Data Fetcher</strong></p><p>Fetch a value from a dictionary by key.<br> — Handle KeyError and return a default message<br> — Log access errors for missing keys<br> — Raise exception if dictionary is empty</p><p>6.<strong> File Upload Validator</strong></p><p>Validate file format and size.<br> — Raise ValueError for unsupported formats (e.g., .exe)<br> — Raise custom FileTooLargeException if size &gt; 5MB<br> — Catch both and return meaningful feedback</p><p>7. <strong>Student Grade Calculator</strong></p><p>Read marks from user, compute grade.<br> — Handle non-integer input (ValueError)<br> — Handle marks outside valid range (0–100)<br> — Raise custom exceptions for invalid scores</p><p>8. <strong>Database Connection Simulator</strong></p><p>Simulate a DB connection (no real DB needed).<br> — If credentials are wrong, raise PermissionError<br> — If DB not found, raise ConnectionError<br> — Use finally block to ‘close’ the connection</p><p>9.<strong> E-Commerce Cart Price Calculator</strong></p><p>Calculate total from cart list (item name, price, quantity).<br> — Handle missing price or quantity with KeyError<br> — Handle type errors (e.g., string instead of int)<br> — Use try-except to process the cart smoothly</p><p>10. <strong>Exception Logger Utility</strong></p><p>Create a utility function log_exception(e) that:<br> — Accepts an exception object<br> — Logs error type, message, and timestamp to a file<br> — Can be reused in any except block</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=533fc222e31b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Functions]]></title>
            <link>https://medium.com/@chaitanya4a3/python-functions-28dc99d66176?source=rss-534f3edae7ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/28dc99d66176</guid>
            <category><![CDATA[functions-in-python]]></category>
            <category><![CDATA[basic-python]]></category>
            <category><![CDATA[def]]></category>
            <category><![CDATA[python-functions]]></category>
            <category><![CDATA[function-return]]></category>
            <dc:creator><![CDATA[Krishna Chaitanya]]></dc:creator>
            <pubDate>Fri, 27 Jun 2025 17:52:41 GMT</pubDate>
            <atom:updated>2025-06-28T06:17:09.440Z</atom:updated>
            <content:encoded><![CDATA[<p>1. Python function — definition with example</p><p>2. Usage of functions</p><p>3. List of Python functions:</p><p>- Predefined functions with examples</p><p>- User-defined functions:</p><p>- General function (no params, no return)</p><p>- Function with parameters:</p><p>- Default arguments</p><p>- Keyword arguments</p><p>- Positional arguments</p><p>- Arbitrary arguments (*args, **kwargs)</p><p>- Function with return type</p><p>- Anonymous (lambda) function</p><p>- Recursive function</p><blockquote><strong><em>Function</em>:</strong></blockquote><p>A <strong>function</strong> in Python is a reusable block of code that performs a specific task. Functions help organize code, make it modular, and reduce repetition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*7TGkHnP3LMmKsabCdkvtUg.png" /></figure><p>Syntax:</p><p>def function_name(parameters):</p><p>statement(s)</p><p>Example:</p><p>def greet():</p><p>print(“Hello, World!”)</p><p>greet() # Output: Hello, World!</p><h3>2. What is the Use of Functions?</h3><p>- Avoid code repetition</p><p>- Increase modularity and readability</p><p>- Easy debugging and maintenance</p><p>- Encourages reuse of code</p><h4>3. List of Python Functions</h4><h4>3.1 Predefined Function Definition with Examples</h4><p>These are built-in functions provided by Python.</p><p>Examples:</p><p>print(“Hello”) # Output: Hello</p><p>len(“Python”) # Output: 6</p><p>type(10.5) # Output: &lt;class ‘float’&gt;</p><p>sorted([3, 1, 2]) # Output: [1, 2, 3]</p><p>sum([1, 2, 3]) # Output: 6</p><h4>3.2 User Defined Functions</h4><h4>3.2.1 General Function — Without Parameters and No Return Type</h4><p>Syntax:</p><p>def function_name():</p><p>statements</p><p>Example:</p><p>def say_hello():</p><p>print(“Hello!”)</p><p>say_hello()</p><h4>3.2.2 Python Function with Parameters</h4><h4>a. Default Arguments</h4><p>def greet(name=”User”):</p><p>print(“Hello,”, name)</p><p>greet() # Output: Hello, User</p><p>greet(“Krishna”)</p><p># Output: Hello, Krishna</p><h4>b. Keyword Arguments (Named Arguments)</h4><p>def student(name, age):</p><p>print(“Name:”, name)</p><p>print(“Age:”, age)</p><p>student(age=25, name=”Moni”)</p><h4>c. Positional Arguments</h4><p>def add(a, b):</p><p>print(a + b)</p><p>add(3, 5)</p><p># Output: 8</p><h4>d. Arbitrary Arguments (Variable-Length Arguments)</h4><p><strong>Using *args:</strong></p><p>def total_sum(*numbers):</p><p>print(sum(numbers))</p><p>total_sum(1, 2, 3, 4) # Output: 10</p><p><strong>Using **kwargs:</strong></p><p>def display_info(**info):</p><p>for key, value in info.items():</p><p>print(f”{key}: {value}”)</p><p>display_info(name=”Chaitanya”, age=30)</p><h4>3.2.3 Python Function with Return Type</h4><p>def multiply(x, y):</p><p>return x * y</p><p>result = multiply(4, 5)</p><p>print(result)</p><p># Output: 20</p><h4>3.3 Anonymous Function / Lambda Function</h4><p>A lambda function is a small, unnamed function defined using the lambda keyword.</p><p>Syntax:</p><p>lambda arguments: expression</p><p>Example:</p><p>double = lambda x: x * 2</p><p>print(double(5))</p><p># Output: 10</p><h4>3.4 Recursive Function</h4><p>A recursive function is one that calls itself within its definition.</p><p>Example:</p><p>def factorial(n):</p><p>if n == 0:</p><p>return 1</p><p>else:</p><p>return n * factorial(n — 1)</p><p>print(factorial(5))</p><p># Output: 120</p><blockquote><strong><em>Interview Questions on Python Functions</em></strong></blockquote><ol><li>What is the difference between a function and a method in Python?</li><li>What are the different types of arguments in Python functions?</li><li>What are *args and **kwargs? When would you use them?</li><li>How does Python handle default argument values?</li><li>What is the difference between a return statement and print?</li><li>Explain lambda functions. How are they different from regular functions?</li><li>Can a function return multiple values?</li><li>What is recursion? Give a real-time use case.</li><li>How do Python’s built-in functions help in day-to-day coding?</li><li>What are the advantages of using functions in large codebases?</li></ol><blockquote><strong><em>Tasks for Practice</em></strong></blockquote><ol><li><strong>Create a Calculator</strong> — Use functions for operations like add, subtract, multiply, divide.</li><li><strong>Student Management System</strong> — Use keyword and default arguments to input student data.</li><li><strong>Invoice Generator</strong> — Use return functions and lambda to apply discounts and calculate totals.</li><li><strong>Dynamic Greetings System</strong> — Use arbitrary arguments to greet multiple users.</li><li><strong>Recursive Task</strong> — Write a function to compute Fibonacci numbers recursively.</li><li><strong>Data Processor</strong> — Use *args and **kwargs to handle dynamic data fields.</li><li><strong>Lambda Sorting</strong> — Use lambda to sort a list of dictionaries by a specific key.</li><li><strong>Quiz Application</strong> — Functions to ask questions, validate answers, and keep score.</li><li><strong>String Analyzer</strong> — Function that counts vowels, consonants, spaces, and symbols.</li><li><strong>Bank Transaction System</strong> — Simulate deposits and withdrawals using functions and return values.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28dc99d66176" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Control Flow Statements and Loops]]></title>
            <link>https://medium.com/@chaitanya4a3/python-control-flow-statements-and-loops-fde40ac2953f?source=rss-534f3edae7ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/fde40ac2953f</guid>
            <category><![CDATA[python-control-flow]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[while-loop-in-python]]></category>
            <category><![CDATA[for-loop-in-python]]></category>
            <category><![CDATA[if]]></category>
            <dc:creator><![CDATA[Krishna Chaitanya]]></dc:creator>
            <pubDate>Wed, 25 Jun 2025 17:22:31 GMT</pubDate>
            <atom:updated>2025-06-25T17:22:31.905Z</atom:updated>
            <content:encoded><![CDATA[<p>Control flow (or flow of control) is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated.</p><p>The control flow statements are divided into <strong>three categories.</strong></p><ol><li>Conditional statements</li><li>Iterative statements.</li><li>Transfer statements</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*6muCsh4Qx5zYcbiXRvJKXA.png" /></figure><blockquote><strong>Conditional statements:</strong></blockquote><p><strong>Conditional Statements </strong>are allow the program to execute different blocks of code based on whether a condition is true or false. Examples include if, elif and match statements.</p><p>There are three types of conditional statements.</p><ol><li>if statement</li><li>if-else</li><li>if-elif-else</li><li>nested if-else</li></ol><blockquote><strong>if Statement</strong>:</blockquote><p>The if statement is used to test a condition. If the condition is True, the block of code inside the if runs.<br><strong>Syntax</strong>:<br>if condition:<br> indentation # block of code<br>Note: Here indentation is a tab space.<br><strong>Ex</strong>:<br>x = 10<br>if x &gt; 5:<br> print(“x is greater than 5”)</p><p>Output: x is greater than 5</p><blockquote><strong>elif (Else If) Statement</strong></blockquote><p>elif check multiple code blocks. if anyone of elif statement execute the remaning will not execute.</p><p><strong>Syntax</strong>:<br>if condition1:<br> # block of code<br>elif condition2:<br> # block of code</p><p><strong>Ex</strong>:<br>x = 10<br>if x == 5:<br> print(“x is 5”)<br>elif x == 10:<br> print(“x is 10”)</p><p>Output: x is 10</p><blockquote><strong>else statement:</strong></blockquote><p>Incase of if or else statements are not execute else stament code block will execute.</p><p><strong>Syntax</strong>:<br>if condition1:<br> # block of code<br>elif condition2:<br> # block of code<br>else:<br> # block of code</p><p><strong>Ex</strong>:<br>x = 3<br>if x &gt; 10:<br> print(“x is greater than 10”)<br>elif x == 10:<br> print(“x is 10”)<br>else:<br> print(“x is less than 10”)</p><blockquote><strong>Nested if Statement:</strong></blockquote><p>A nested if is an if statement inside another if statement. It’s used when you want to check multiple conditions step by step — one condition inside another.</p><p><strong>Syntax</strong>:<br>if condition1:<br> # block of code for condition1<br> if condition2:<br> # block of code for condition2<br> …</p><p><strong>Ex</strong>:<br>x = 15</p><p>if x &gt; 10:<br> print(“x is greater than 10”)<br> if x &lt; 20:<br> print(“x is also less than 20”)<br> else:<br> print(“x is 20 or more”)<br>else:<br> print(“x is 10 or less”)</p><p>Output:<br>x is greater than 10<br>x is also less than 20</p><blockquote><strong>Ternary Operator (Conditional Expression):</strong></blockquote><p>The ternary operator allows you to write if-else logic in a single line. It’s used to assign a value based on a condition.</p><p><strong>Syntax</strong>:<br>value_if_true if condition else value_if_false</p><p><strong>Ex</strong>:<br>x = 10<br>result = “Even” if x % 2 == 0 else “Odd”<br>print(result)<br>Output: Even</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*NUkgQecabbf9F36rmTbCVg.png" /></figure><blockquote><strong>Match case statement:</strong></blockquote><p>match-case is a <strong>pattern matching</strong> statement that lets you compare a variable against a series of patterns (like values, types, or structures) and execute corresponding blocks of code.</p><p><strong>Syntax</strong>:<br>match variable:<br> case pattern1:<br> # code block<br> case pattern2:<br> # code block<br> case _:<br> # default case (like ‘else’)</p><p><strong>Ex</strong>:<br>day = “Monday”</p><p>match day:<br> case “Monday”:<br> print(“Start of the work week.”)<br> case “Friday”:<br> print(“Last work day of the week.”)<br> case _:<br> print(“It’s a regular day.”)</p><blockquote><strong>Python looping statements:</strong></blockquote><p>Loops are used to <strong>repeat a block of code multiple times</strong> based on a condition or an iterable.</p><p>Python provides two main types of loops:</p><ol><li>for loop</li><li>while loop</li></ol><p><strong>Syntax</strong>:<br>for variable in sequence:<br> # block of code</p><p><strong>Ex</strong>:<br>1. fruits = [“apple”, “banana”, “cherry”]<br>for fruit in fruits:<br> print(fruit)</p><p>for i in range(1, 6):<br> print(i)</p><blockquote><strong>While Loop:</strong></blockquote><p>The while loop keeps executing the block of code <strong>as long as the given condition is True</strong>.</p><p><strong>Syntax</strong>:<br>while condition:<br> # block of code</p><p><strong>Ex</strong>:<br>i = 1<br>while i &lt;= 5:<br> print(i)<br> i += 1</p><blockquote><strong>break Statement:</strong></blockquote><p>break is used to <strong>exit a loop prematurely</strong> when a certain condition is met.</p><p><strong>Ex</strong>:<br>for i in range(10):<br> if i == 5:<br> break<br> print(i)</p><p>Output: 0 1 2 3 4</p><blockquote><strong>Continue Statement:</strong></blockquote><p>continue skips the current iteration and moves to the next one.</p><p>Ex;<br>for i in range(5):<br> if i == 2:<br> continue<br> print(i)</p><p>Output: 0 1 3 4</p><blockquote><strong>else with Loop Statement:</strong></blockquote><p>Python allows an optional <strong>else </strong>block <strong>after a loop</strong>, which runs <strong>only if the loop completes normally (no </strong><strong>break).</strong></p><p><strong>Ex</strong>:<br>for i in range(3):<br> print(i)<br>else:<br> print(“Loop finished without break.”)</p><p><strong>Output</strong>: <br>0<br>1<br>2<br>Loop finished without break.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*L140P78TpErwix0V10tz_A.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fde40ac2953f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Data Types]]></title>
            <link>https://medium.com/@chaitanya4a3/python-data-types-626bb889317b?source=rss-534f3edae7ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/626bb889317b</guid>
            <category><![CDATA[python-tuple]]></category>
            <category><![CDATA[python-data-type]]></category>
            <category><![CDATA[python-list-methods]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-list]]></category>
            <dc:creator><![CDATA[Krishna Chaitanya]]></dc:creator>
            <pubDate>Mon, 23 Jun 2025 16:58:16 GMT</pubDate>
            <atom:updated>2025-06-24T16:53:30.102Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>Data Type:</strong></blockquote><p>A <strong>data type</strong> is a classification that tells a programming language what kind of value a variable holds and what operations can be performed on it.</p><blockquote><strong>Common Python Data Types:</strong></blockquote><p>Python has several built-in data types, which can be grouped into categories:</p><p>1. <strong>Numeric Types</strong></p><p><strong>int </strong>— Integer values<br> Example: 10, -3</p><p><strong>float </strong>— Floating-point (decimal) numbers<br> Example: 3.14, -0.001</p><p><strong>complex </strong>— Complex numbers<br> Example: 2 + 3j</p><p>2. <strong>Text Type</strong></p><p><strong>str </strong>— String (text)<br> Example: “hello”, ‘Python’</p><p>3. <strong>Boolean Type</strong></p><p><strong>bool </strong>— Boolean values<br> Example: True, False</p><p>4. <strong>Sequence Types</strong></p><p><strong>list </strong>— Ordered, mutable collection<br> Example: [1, 2, 3]</p><p><strong>tuple </strong>— Ordered, immutable collection<br> Example: (1, 2, 3)</p><p><strong>range </strong>— Sequence of numbers<br> Example: range(0, 5)</p><p>5. <strong>Set Types</strong></p><p><strong>set </strong>— Unordered, unique values<br> Example: {1, 2, 3}</p><p><strong>frozenset </strong>— Immutable version of a set</p><p>6. <strong>Mapping Type</strong></p><p><strong>dict </strong>— Key-value pairs<br> Example: {“name”: “Alice”, “age”: 25}</p><p>7. <strong>Binary Types</strong></p><p><strong>bytes</strong>, <strong>bytearray</strong>, <strong>memoryview </strong>— For handling binary data</p><p>8. <strong>None Type</strong></p><p><strong>None </strong>Type — Represents the absence of a value<br> Example: None</p><p><strong>Note</strong>: Python is a dynamically type programming language. We can asign data to a variable without specifying data type.</p><p><strong>Example</strong>:</p><p>name = “Alice” # str<br>age = 30 # int<br>height = 5.6 # float<br>is_student = False # bool<br>scores = [90, 85, 88] # list<br>person = {“name”: “Alice”, “age”: 30} # dict</p><blockquote><strong>Check data type of a variable:</strong></blockquote><p>To check the data type of a variable in Python, use the built-in type() function.</p><p>Example:</p><p>x = 42<br>print(type(x)) # Output: &lt;class ‘int’&gt;</p><p>y = “Hello”<br>print(type(y)) # Output: &lt;class ‘str’&gt;</p><blockquote><strong>Collection Data Types:</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*lT5z8wOdX9pIeONkInxCSw.png" /></figure><blockquote><strong>Differences</strong>:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*DEP2FZF6GrYM_NAST_OiSg.png" /></figure><blockquote><strong>Performance</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*gk7iGfCGsQ-htORqn32aTA.png" /></figure><blockquote><strong>List data type:</strong></blockquote><p>A <strong>list</strong> in Python is a <strong>mutable</strong>, <strong>ordered</strong> collection of items. It can hold items of <strong>different data types</strong>, including other lists.</p><p><strong>Example</strong>:</p><p>my_list = [10, “hello”, 3.14, True]<br>print(my_list)<br>Output: [10, ‘hello’, 3.14, True]</p><p><strong>Properties of a List:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*9fUSFRWWkBMvQ5tStygYgQ.png" /></figure><p><strong>List Methods:</strong></p><p>1. <strong>append(x)</strong>: <strong>Adds a single item x to the end of the list.</strong></p><p>fruits = [‘apple’, ‘banana’]<br> fruits.append(‘cherry’)<br> print(fruits)</p><p>Output: [‘apple’, ‘banana’, ‘cherry’]</p><p>2. <strong>extend(iterable)</strong>: Adds all elements of an iterable (like a list) to the end of the list.</p><p>fruits = [‘apple’]<br> fruits.extend([‘banana’, ‘cherry’])<br> print(fruits)</p><p>Output: [‘apple’, ‘banana’, ‘cherry’]</p><p>3.<strong> insert(i, x): </strong>Inserts item x at index i.</p><p>fruits = [‘apple’, ‘cherry’]<br> fruits.insert(1, ‘banana’)<br> print(fruits)</p><p>Output: [‘apple’, ‘banana’, ‘cherry’]</p><p>4. <strong>remove(x)</strong>: Removes the first occurrence of item x.</p><p>numbers = [1, 2, 3, 2]<br> numbers.remove(2)<br> print(numbers)</p><p>Output: [1, 3, 2]</p><p>5. <strong>pop([i])</strong>: Removes and returns the item at index i. If i is not provided, removes the last item.</p><p>fruits = [‘apple’, ‘banana’, ‘cherry’]<br> last = fruits.pop()<br> print(last)</p><p>Output: cherry<br> print(fruits)</p><p>Output: [‘apple’, ‘banana’]<br> <br> item = fruits.pop(0)<br> print(item)</p><p>Output: apple</p><p>6. <strong>clear()</strong>: Removes all items from the list.</p><p>fruits = [‘apple’, ‘banana’]<br> fruits.clear()<br> print(fruits)</p><p>Output: []</p><p>7. <strong>index(x)</strong>: Returns the first index of item x.</p><p>colors = [‘red’, ‘blue’, ‘green’, ‘blue’]<br> print(colors.index(‘blue’))</p><p>Output: 1</p><p>8. <strong>count(x)</strong>: Returns the number of times item x appears.</p><p>nums = [1, 2, 3, 2, 2]<br> print(nums.count(2))</p><p>Output: 3</p><p>9. <strong>sort()</strong>: Sorts the list in place in ascending order.</p><p>nums = [3, 1, 4, 2]<br> nums.sort()<br> print(nums)</p><p>Output: [1, 2, 3, 4]</p><p>10. <strong>reverse()</strong>: Reverses the elements in place.</p><p>letters = [‘a’, ‘b’, ‘c’]<br> letters.reverse()<br> print(letters)</p><p>Output: [‘c’, ‘b’, ‘a’]</p><p>11. <strong>copy()</strong>: Returns a shallow copy of the list.</p><p>original = [1, 2, 3]<br> copied = original.copy()<br> print(copied)</p><p>Output: [1, 2, 3]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*V9SNPTOu1jvGSCgZX6Ewag.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*GCUBsd6Y0Ha_CGSb7-e3Gw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*Lfb2OqTLRYPZJB_gLYpzYQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=626bb889317b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Introduction]]></title>
            <link>https://medium.com/@chaitanya4a3/python-introduction-d7ffdb29bbc4?source=rss-534f3edae7ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7ffdb29bbc4</guid>
            <category><![CDATA[python-data-type]]></category>
            <category><![CDATA[history-python]]></category>
            <category><![CDATA[python-introduction]]></category>
            <category><![CDATA[python-operator]]></category>
            <dc:creator><![CDATA[Krishna Chaitanya]]></dc:creator>
            <pubDate>Sun, 22 Jun 2025 17:40:49 GMT</pubDate>
            <atom:updated>2025-06-22T17:40:49.824Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>What is a Framework?</strong></blockquote><p>A <strong>framework</strong> is a set of tools, libraries, and best practices that provide a foundation for developing software applications. It helps developers write code faster and with fewer errors by providing reusable components.</p><p><strong>Examples</strong>:</p><ul><li><strong>Django </strong>— Full-stack web framework for Python.</li><li><strong>Flask </strong>— Lightweight web framework for APIs</li><li>Java</li><li>.Net</li></ul><blockquote><strong>What is a Programming Language?</strong></blockquote><p>A <strong>programming language</strong> is a set of instructions used to communicate with computers and create software. It provides rules and syntax for writing programs.</p><p><strong>Examples</strong>:</p><ul><li>Python</li><li>Java</li><li>C++</li><li>C#</li></ul><blockquote><strong>What is Python?</strong></blockquote><p><strong>Python</strong> is a <strong>high-level, interpreted programming language</strong> known for its <strong>simplicity</strong>, <strong>readability</strong>, and <strong>versatility</strong>.</p><blockquote><strong>Key Features:</strong></blockquote><ul><li>Easy-to-read syntax (similar to English)</li><li>Used in Web Development, Data Science, AI, Automation, Scripting</li><li>Large community and tons of libraries</li><li>Open-source and free to use</li></ul><blockquote><strong>History of Python:</strong></blockquote><ul><li>Python was introduced by <strong>Guido van Rossum.</strong></li><li>First released in <strong>1991</strong></li><li>Named after the TV show <em>“Monty Python’s Flying Circus”</em></li></ul><p><strong>Python Applications:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*e6vibYkr_SmPh7wsQ4L13w.png" /></figure><blockquote><strong>Data Types:</strong></blockquote><p>A <strong>datatype</strong> (or <strong>data type</strong>) is a classification that specifies what kind of value a variable can hold and what type of operations can be performed on it.</p><ol><li><strong>Value Types (Primitive or Basic Data Types):</strong></li></ol><p>These store the actual value directly in memory, and each variable holds its own copy of the data. Changing one variable doesn’t affect others. These are <strong>immutable</strong>: once created, their value cannot be changed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*kIV4m4pJ5CtSrlZ3mLu5sw.png" /></figure><p><strong>2. Reference Types (Non-Primitive Data Types):</strong></p><p>These store <strong>references (or addresses) to the actual data</strong> in memory. If multiple variables refer to the same object, changing the object via one variable affects all others.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*KFMYBQvj_yEM--sB_rVl4w.png" /></figure><p><strong>Differences Between Value Type and Reference Type:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*xC6kkEJ9eqaZSSDg_9F07A.png" /></figure><blockquote><strong>Input / Output in Python:</strong></blockquote><p><strong>input() </strong>— Take input from user</p><p>name = input(“Enter your name: “)<br>print(“Hello ”, name)</p><p><strong>print()</strong> — Output to screen.</p><p>print(“Hello, World!”) # Output: Hello, World!<br>print(5 + 3) # Output: 8</p><blockquote><strong>Type Conversion: </strong><em>Used to </em><strong><em>convert</em></strong><em> data from one type to another.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*MPRUpXGqrfoChNzRmtay1g.png" /></figure><p><strong>Example:</strong></p><p>age = input(“Enter your age: “) # input as string<br>age = int(age) # convert to integer<br>print(“Next year, you will be”, age + 1)<br>price = float(input(“Enter price: “))<br>print(“Total price with tax:”, price * 1.18)</p><blockquote><strong>Operators in Python:</strong></blockquote><p>An <strong>operator</strong> is a <strong>symbol</strong> that tells the interpreter to perform <strong>specific mathematical or logical operations</strong> on values (called operands).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*zTLu68v5Uik02MNnXot9bg.png" /></figure><p><strong>Why Use Operators?</strong></p><ul><li>To compare values: ==, &lt;, &gt;</li><li>To perform calculations: +, -, *</li><li>To combine logic: and, or, not</li><li>To assign and modify values: =, +=, etc.</li></ul><blockquote><strong>Arithmetic Operators: </strong><em>Used for basic mathematical operations.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*3UoBA7kIw_-CMTIWVAcTRg.png" /></figure><blockquote><strong>Assignment Operators: </strong><em>Used to assign or update values.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*DwaqMSYe6AQ-5mdWb2_6sg.png" /></figure><blockquote><strong>Comparison Operators: </strong><em>Used to compare two values.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*x55mDv4UGtP5g2rGR-sYkA.png" /></figure><blockquote><strong>Logical Operators: </strong><em>Used to combine conditional statements.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*lugEixtz6wFpTRmexOM71w.png" /></figure><blockquote><strong>Bitwise Operators: </strong><em>Operate at the </em><strong><em>binary level</em></strong><em>.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*qFNFDC5w4ak4G6tf8UmEiQ.png" /></figure><blockquote><strong>Membership Operators: </strong><em>Test for presence in sequences like lists, strings, etc.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*cWCZipR_KAa8U12zrwnPTQ.png" /></figure><blockquote><strong>Identity Operators: </strong><em>Check if two variables point to the </em><strong><em>same object</em></strong><em> in memory.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*692WK4V9ptPos2JoA707Zg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7ffdb29bbc4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>