<?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 SONALI BALLA on Medium]]></title>
        <description><![CDATA[Stories by SONALI BALLA on Medium]]></description>
        <link>https://medium.com/@sonaliballa?source=rss-33ceab3e2a99------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*QwgbIWK_H72lm_2u</url>
            <title>Stories by SONALI BALLA on Medium</title>
            <link>https://medium.com/@sonaliballa?source=rss-33ceab3e2a99------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 09:36:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sonaliballa/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 Modules & Packages: Organizing and Reusing Code]]></title>
            <link>https://sonaliballa.medium.com/python-modules-packages-organizing-and-reusing-code-9352813facf9?source=rss-33ceab3e2a99------2</link>
            <guid isPermaLink="false">https://medium.com/p/9352813facf9</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[python-packages]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[python-module]]></category>
            <dc:creator><![CDATA[SONALI BALLA]]></dc:creator>
            <pubDate>Thu, 01 Oct 2026 08:47:38 GMT</pubDate>
            <atom:updated>2026-10-01T08:47:38.477Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rNUAj90Le_ZcnXWlAf3U1A.png" /></figure><blockquote>Day 8 of my Generative AI Learning Journey</blockquote><p>As I continue my <strong>Python learning journey for Generative AI</strong>, today I’m learning about <strong>Modules and Packages</strong>.</p><p>So far, I’ve been writing Python programs using variables, conditions, loops, functions, data structures, file handling, and OOP.</p><p>But as projects become bigger, keeping everything inside one file can become difficult.</p><p>That’s where <strong>modules and packages</strong> become useful.</p><blockquote><strong><em>Modules and packages help us organize, reuse, and manage Python code efficiently.</em></strong></blockquote><p>And this becomes especially useful when working on larger <strong>Machine Learning and Generative AI projects</strong>.</p><h4>What is a Module?</h4><p>A <strong>module</strong> is simply a Python file containing code that we can reuse in another Python program.</p><p>A Python file with a .py extension can be used as a module.</p><p>For example, let’s create a file called:</p><pre>calculator.py</pre><p>Inside it:</p><pre>def add(a, b):<br>    return a + b</pre><pre>def subtract(a, b):<br>    return a - b</pre><p>Now we can use these functions in another Python file.</p><h4>Importing a Module</h4><p>Suppose our second file is:</p><pre>main.py</pre><p>We can import the module:</p><pre>import calculator</pre><p>Then:</p><pre>print(calculator.add(10, 5))<br>print(calculator.subtract(10, 5))</pre><p>Output:</p><pre>15<br>5</pre><p>Instead of rewriting the functions, we simply <strong>reuse them</strong>.</p><h4>Why Use Modules?</h4><p>Modules help us:</p><ul><li>Reuse code</li><li>Organize code</li><li>Avoid repetition</li><li>Make programs easier to maintain</li><li>Separate different parts of an application</li></ul><p>For example, instead of creating one huge Python file:</p><pre>app.py</pre><p>we can organize our project like:</p><pre>project/<br>│<br>├── main.py<br>├── data.py<br>├── model.py<br>├── utils.py<br>└── config.py</pre><p>Each file can have a specific purpose.</p><p>This makes the project easier to understand and manage.</p><h4>Built-in Python Modules</h4><p>Python already provides many useful modules.</p><p>Some commonly used modules are:</p><ul><li>math</li><li>random</li><li>datetime</li><li>os</li><li>json</li><li>re</li></ul><p>Let’s look at a few examples.</p><h4>The math Module</h4><p>The math module provides mathematical functions.</p><pre>import math</pre><pre>print(math.sqrt(25))<br>print(math.pi)</pre><p>Output:</p><pre>5.0<br>3.141592653589793</pre><h4>The random Module</h4><p>The random module allows us to generate random values.</p><pre>import random</pre><pre>number = random.randint(1, 10)</pre><pre>print(number)</pre><p>Every time we run the program, we may get a different number.</p><h4>The datetime Module</h4><p>The datetime module helps us work with dates and times.</p><pre>from datetime import datetime</pre><pre>current_time = datetime.now()</pre><pre>print(current_time)</pre><p>This can be useful when applications need timestamps.</p><h4>The json Module</h4><p>The json module is especially useful when working with structured data.</p><pre>import json</pre><pre>data = {<br>    &quot;name&quot;: &quot;Sonali&quot;,<br>    &quot;role&quot;: &quot;Gen AI Learner&quot;<br>}</pre><pre>json_data = json.dumps(data)</pre><pre>print(json_data)</pre><p>Output:</p><pre>{&quot;name&quot;: &quot;Sonali&quot;, &quot;role&quot;: &quot;Gen AI Learner&quot;}</pre><p>JSON is widely used when working with <strong>APIs and web applications</strong>.</p><h4>What is a Package?</h4><p>A <strong>package</strong> is a collection of related Python modules organized together.</p><p>Think of it like this:</p><pre>Module → One Python file</pre><pre>Package → Collection of related modules</pre><p>For example:</p><pre>my_project/<br>│<br>├── main.py<br>│<br>└── utils/<br>    ├── text.py<br>    ├── data.py<br>    └── model.py</pre><p>Here, utils organizes multiple related modules.</p><p>Packages become particularly useful as projects grow.</p><h4>Why Are Packages Useful?</h4><p>Imagine building a Gen AI application.</p><p>You might have different components for:</p><pre>Gen AI Application<br>│<br>├── Data Processing<br>├── Prompt Handling<br>├── Embeddings<br>├── Model Interaction<br>├── Retrieval<br>└── Utilities</pre><p>Instead of keeping all the code in one file, we can organize each part separately.</p><p>This makes the project easier to understand, maintain, and expand.</p><h4>Importing Specific Functions</h4><p>Instead of importing the entire module:</p><pre>import math</pre><p>we can import a specific function:</p><pre>from math import sqrt</pre><pre>print(sqrt(25))</pre><p>This is another common way of importing code.</p><h4>Importing With an Alias</h4><p>We can also give a module a shorter name using as.</p><p>For example:</p><pre>import numpy as np</pre><p>Here:</p><pre>numpy → Module<br>np → Alias</pre><p>Then we can write:</p><pre>array = np.array([1, 2, 3])</pre><p>You’ll see this style frequently in <strong>Data Science, Machine Learning, and Gen AI</strong>.</p><h4>Third-Party Libraries</h4><p>Python also has thousands of libraries created by developers around the world.</p><p>Some important libraries I’ll use in my Gen AI journey include:</p><pre>NumPy<br>Pandas<br>Matplotlib<br>Scikit-learn<br>TensorFlow<br>PyTorch<br>Transformers</pre><p>These libraries provide functionality that would take a huge amount of time to build from scratch.</p><p>Instead of creating everything ourselves, we can use existing libraries.</p><h4>Installing Packages with pip</h4><p>Python uses <strong>pip</strong> to install many third-party packages.</p><p>For example:</p><pre>pip install numpy</pre><p>For Pandas:</p><pre>pip install pandas</pre><p>For Matplotlib:</p><pre>pip install matplotlib</pre><p>After installation, we can import them into our Python programs.</p><p>For example:</p><pre>import numpy as np<br>import pandas as pd</pre><h4>What is a Virtual Environment?</h4><p>When working on different Python projects, different projects may require different package versions.</p><p>A <strong>virtual environment</strong> creates an isolated Python environment for a project.</p><p>For example:</p><pre>python -m venv myenv</pre><p>On Windows, we can activate it using:</p><pre>myenv\Scripts\activate</pre><p>Now packages installed inside this environment can be managed separately from other projects.</p><p>This is especially useful when working on multiple Python or Gen AI projects.</p><h4>How Modules &amp; Packages Connect to Gen AI</h4><p>This is where today’s topic becomes important for my Gen AI journey.</p><p>A real Gen AI application may contain many components.</p><p>For example:</p><pre>Gen AI Application<br>        ↓<br>Data Processing<br>        ↓<br>Prompt Engineering<br>        ↓<br>Embeddings<br>        ↓<br>Vector Database<br>        ↓<br>Retrieval<br>        ↓<br>LLM<br>        ↓<br>Response</pre><p>Each part can be separated into different modules.</p><p>For example:</p><pre>gen_ai_project/<br>│<br>├── main.py<br>│<br>├── prompts.py<br>│<br>├── embeddings.py<br>│<br>├── retriever.py<br>│<br>├── model.py<br>│<br>└── utils.py</pre><p>This makes the application more organized and easier to maintain.</p><h4>Modules vs Packages</h4><p>Here’s the simple difference:</p><p>ModulePackageUsually a single Python fileCollection of related modules.py fileOrganized directoryContains functions, classes, and variablesContains multiple modulesUseful for smaller pieces of codeUseful for larger projects</p><p>The easiest way to remember it:</p><blockquote><strong><em>Module = One Python file</em></strong></blockquote><blockquote><strong><em>Package = Collection of modules</em></strong></blockquote><h4>What I Learned Today</h4><p>Today I learned:</p><ul><li>What a module is</li><li>How to create a module</li><li>How to import modules</li><li>Built-in Python modules</li><li>import</li><li>from ... import</li><li>Import aliases</li><li>What packages are</li><li>Third-party packages</li><li>pip</li><li>Virtual environments</li><li>How modules and packages help organize Gen AI projects</li></ul><h4>My Gen AI Learning Journey</h4><p>Here is my progress so far:</p><pre>✅ Python Basics<br>✅ Variables, Data Types, Operators, Input &amp; Output<br>✅ Conditional Statements &amp; Loops<br>✅ Functions<br>✅ Data Structures<br>✅ File Handling &amp; Exception Handling<br>✅ Classes, Objects &amp; OOP<br>✅ Modules &amp; Package</pre><h4>What’s Next?</h4><p>In the next article, I’ll start learning <strong>NumPy</strong>.</p><p>NumPy is one of the most important Python libraries for working with numerical data and forms an important foundation for <strong>Data Science and Machine Learning</strong>.</p><p>The journey continues:</p><p><strong>Python → NumPy → Pandas → ML → Deep Learning → Transformers → LLMs → RAG → AI Agents → Gen AI Projects</strong></p><h4>Tags</h4><p>Python Generative AI GenAI Artificial Intelligence Machine Learning Python Programming Python Modules Python Packages Learning in Public</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9352813facf9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Classes, Objects & Reusable Code]]></title>
            <link>https://sonaliballa.medium.com/understanding-classes-objects-reusable-code-79e5d150a0bb?source=rss-33ceab3e2a99------2</link>
            <guid isPermaLink="false">https://medium.com/p/79e5d150a0bb</guid>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[class]]></category>
            <category><![CDATA[objects]]></category>
            <category><![CDATA[python-oops-concept]]></category>
            <dc:creator><![CDATA[SONALI BALLA]]></dc:creator>
            <pubDate>Tue, 29 Sep 2026 15:41:19 GMT</pubDate>
            <atom:updated>2026-09-29T15:41:19.575Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_C3F1M1Lxjmea3o7eH-HEQ.png" /></figure><blockquote>Day 7 of My Generative AI Learning Journey</blockquote><p>As I continue my <strong>Python journey for Generative AI</strong>, I’ve reached an important topic: <strong>Object-Oriented Programming (OOP)</strong>.</p><p>At first, terms like <em>class, object, inheritance, encapsulation,</em> and <em>polymorphism</em> can sound complicated.</p><p>But the basic idea is actually simple:</p><blockquote><strong><em>OOP helps us organize our code around objects and their behavior.</em></strong></blockquote><p>And as we move toward APIs, AI applications, LLMs, RAG systems, and AI agents, understanding OOP becomes increasingly useful.</p><h4>What is Object-Oriented Programming?</h4><p><strong>Object-Oriented Programming (OOP)</strong> is a programming approach where we organize programs using <strong>objects</strong>.</p><p>An object can contain:</p><ul><li>Data → <strong>attributes</strong></li><li>Behavior → <strong>methods</strong></li></ul><p>For example, imagine an AI chatbot.</p><p>A chatbot could have:</p><ul><li>name</li><li>model</li><li>conversation history</li></ul><p>And it could perform actions such as:</p><ul><li>send a message</li><li>receive a response</li><li>clear conversation history</li></ul><p>Instead of keeping everything as separate variables and functions, we can organize them inside a <strong>class</strong>.</p><h4>What is a Class?</h4><p>A <strong>class</strong> is like a blueprint for creating objects.</p><p>For example:</p><pre>class Student:<br>    pass</pre><p>Here, Student is a class.</p><p>Think of a class as a blueprint.</p><p>🏠 Blueprint → House<br>📦 Class → Object</p><p>The class describes what an object should contain.</p><h4>What is an Object?</h4><p>An <strong>object</strong> is an instance of a class.</p><pre>class Student:<br>    pass</pre><pre>student1 = Student()<br>student2 = Student()</pre><p>Here:</p><ul><li>Student → class</li><li>student1 → object</li><li>student2 → object</li></ul><p>We can create many objects from the same class.</p><h4>The __init__() Method</h4><p>The __init__() method is used to initialize an object&#39;s data when the object is created.</p><p>Example:</p><pre>class Student:</pre><pre>    def __init__(self, name, age):<br>        self.name = name<br>        self.age = age</pre><p>Now we can create an object:</p><pre>student1 = Student(&quot;Sonali&quot;, 22)</pre><pre>print(student1.name)<br>print(student1.age)</pre><p>Output:</p><pre>Sonali<br>22</pre><h4>What is self?</h4><p>self refers to the <strong>current object</strong>.</p><p>For example:</p><pre>self.name = name</pre><p>means:</p><blockquote><em>Store the value of </em><em>name inside this particular object.</em></blockquote><p>Different objects can therefore have different values.</p><pre>student1 = Student(&quot;Sonali&quot;, 22)<br>student2 = Student(&quot;Rahul&quot;, 23)</pre><p>Each object has its own data.</p><h4>What are Methods?</h4><p>A <strong>method</strong> is a function defined inside a class.</p><p>Example:</p><pre>class Student:</pre><pre>    def __init__(self, name):<br>        self.name = name</pre><pre>    def introduce(self):<br>        print(f&quot;Hi, I am {self.name}&quot;)</pre><p>Now:</p><pre>student1 = Student(&quot;Sonali&quot;)</pre><pre>student1.introduce()</pre><p>Output:</p><pre>Hi, I am Sonali</pre><p>So:</p><p><strong>Attributes → store information</strong></p><p><strong>Methods → perform actions</strong></p><h4>The Four Main Concepts of OOP</h4><p>The four commonly discussed pillars of OOP are:</p><ol><li>Encapsulation</li><li>Inheritance</li><li>Polymorphism</li><li>Abstraction</li></ol><p>Let’s understand them simply.</p><h4>Encapsulation</h4><p><strong>Encapsulation</strong> means keeping data and the methods that operate on that data together inside a class, while controlling how that data is accessed.</p><p>Example:</p><pre>class BankAccount:</pre><pre>    def __init__(self, balance):<br>        self.balance = balance</pre><pre>    def deposit(self, amount):<br>        self.balance += amount</pre><pre>    def show_balance(self):<br>        print(self.balance)</pre><p>Now:</p><pre>account = BankAccount(5000)</pre><pre>account.deposit(1000)</pre><pre>account.show_balance()</pre><p>Output:</p><pre>6000</pre><p>The class controls how the balance is modified.</p><h4>Inheritance</h4><p><strong>Inheritance</strong> allows one class to reuse properties and methods from another class.</p><p>Example:</p><pre>class Animal:</pre><pre>    def eat(self):<br>        print(&quot;Animal is eating&quot;)</pre><p>Create another class:</p><pre>class Dog(Animal):</pre><pre>    def bark(self):<br>        print(&quot;Dog is barking&quot;)</pre><p>Now:</p><pre>dog = Dog()</pre><pre>dog.eat()<br>dog.bark()</pre><p>Output:</p><pre>Animal is eating<br>Dog is barking</pre><p>The Dog class inherited the eat() method from Animal.</p><h4>Why is inheritance useful?</h4><p>It helps us:</p><ul><li>reuse code</li><li>reduce duplication</li><li>create relationships between classes</li><li>organize larger applications</li></ul><h4>Polymorphism</h4><p><strong>Polymorphism</strong> means that the same method or interface can behave differently depending on the object.</p><p>Example:</p><pre>class Dog:</pre><pre>    def sound(self):<br>        print(&quot;Bark&quot;)<br></pre><pre>class Cat:</pre><pre>    def sound(self):<br>        print(&quot;Meow&quot;)</pre><p>Now:</p><pre>dog = Dog()<br>cat = Cat()</pre><pre>dog.sound()<br>cat.sound()</pre><p>Output:</p><pre>Bark<br>Meow</pre><p>Both objects have a sound() method, but they behave differently.</p><h4>Abstraction</h4><p><strong>Abstraction</strong> means hiding unnecessary implementation details and exposing only what is needed.</p><p>Think about using an AI application.</p><p>You might call:</p><pre>response = model.generate(&quot;Explain AI&quot;)</pre><p>You don’t necessarily need to know every internal step happening inside the model.</p><p>The complicated implementation is hidden behind a simpler interface.</p><p>That’s the basic idea of abstraction.</p><h4>Class Variables vs Instance Variables</h4><p>There are two important types of variables you should understand.</p><h4>Instance Variable</h4><p>Belongs to a particular object.</p><pre>class Student:</pre><pre>    def __init__(self, name):<br>        self.name = name</pre><p>Each student can have a different name.</p><h4>Class Variable</h4><p>Shared by the class.</p><pre>class Student:</pre><pre>    school = &quot;ABC School&quot;</pre><pre>    def __init__(self, name):<br>        self.name = name</pre><p>Now:</p><pre>student1 = Student(&quot;Sonali&quot;)<br>student2 = Student(&quot;Rahul&quot;)</pre><pre>print(student1.school)<br>print(student2.school)</pre><p>Both objects can access the same class variable.</p><h4>Why OOP Matters in Gen AI</h4><p>This is where OOP becomes interesting for my <strong>Generative AI journey</strong>.</p><p>Gen AI applications can become complex.</p><p>A simple application might look like:</p><pre>User<br> ↓<br>Input<br> ↓<br>Prompt<br> ↓<br>Model<br> ↓<br>Response</pre><p>But a real application might involve:</p><pre>User<br> ↓<br>Application<br> ↓<br>Prompt Processing<br> ↓<br>Embedding Model<br> ↓<br>Vector Database<br> ↓<br>Retriever<br> ↓<br>LLM<br> ↓<br>Response Processing<br> ↓<br>User</pre><p>Instead of writing everything in one huge Python file, we can organize different components using classes.</p><p>For example:</p><pre>class Chatbot:</pre><pre>    def __init__(self, model):<br>        self.model = model</pre><pre>    def generate_response(self, prompt):<br>        return self.model.generate(prompt)</pre><p>This is only a simplified example, but the idea is important.</p><p>As Gen AI applications become larger, <strong>organized and reusable code becomes extremely valuable</strong>.</p><h4>A Simple Gen AI-Style Example</h4><p>We can create a simple prompt manager:</p><pre>class PromptManager:</pre><pre>    def __init__(self, topic):<br>        self.topic = topic</pre><pre>    def create_prompt(self):<br>        return f&quot;Explain {self.topic} in simple terms.&quot;<br></pre><pre>manager = PromptManager(&quot;Generative AI&quot;)</pre><pre>prompt = manager.create_prompt()</pre><pre>print(prompt)</pre><p>Output:</p><pre>Explain Generative AI in simple terms.</pre><p>Now we have a reusable object for managing prompts.</p><p>Later, the same idea can be extended into more complex systems.</p><h4>OOP in Real Gen AI Applications</h4><p>OOP can be useful when building components such as:</p><ul><li>Chatbot classes</li><li>Prompt managers</li><li>Document processors</li><li>Data loaders</li><li>Embedding utilities</li><li>Vector database interfaces</li><li>RAG pipelines</li><li>AI agents</li><li>API clients</li><li>Model wrappers</li></ul><p>You don’t need to become an OOP expert before starting Gen AI.</p><p>But you should be comfortable reading and writing basic classes.</p><h4>Mini Practice Challenge</h4><p>Try creating a class called AIAssistant.</p><p>It should contain:</p><ul><li>name</li><li>role</li><li>introduce() method</li><li>generate_prompt() method</li></ul><p>For example:</p><pre>assistant = AIAssistant(<br>    &quot;GenAI Assistant&quot;,<br>    &quot;AI Tutor&quot;<br>)</pre><p>The introduce() method could print:</p><pre>I am GenAI Assistant, your AI Tutor.</pre><p>And generate_prompt() could create a prompt based on a topic.</p><p>This is a small exercise, but it helps connect OOP with your Gen AI learning.</p><h4>What I Learned Today</h4><p>Today I learned:</p><ul><li>What OOP is</li><li>Classes</li><li>Objects</li><li>__init__()</li><li>self</li><li>Attributes</li><li>Methods</li><li>Encapsulation</li><li>Inheritance</li><li>Polymorphism</li><li>Abstraction</li><li>Class variables</li><li>Instance variables</li><li>How OOP can be used to organize Gen AI applications</li></ul><p>The biggest takeaway for me is:</p><blockquote><strong><em>OOP is not just about learning syntax. It’s about organizing code so that larger applications become easier to build and maintain</em></strong></blockquote><h4>What’s Next?</h4><p>Next, I’ll learn <strong>Python Modules and Packages</strong>.</p><p>This will help me understand how larger Python projects are structured and how we can reuse code across different files.</p><p>And eventually, these Python fundamentals will connect with the bigger Gen AI ecosystem.</p><p><strong>Python → ML → Deep Learning → Transformers → LLMs → RAG → AI Agents</strong></p><h4>Question for You</h4><p>When you first learned OOP, which concept was the most confusing?</p><p><strong>Classes, objects, inheritance, polymorphism, encapsulation, or abstraction?</strong></p><p>I’d love to know what others found difficult while learning Python.</p><h4>Tags</h4><p>Python Generative AI GenAI Artificial Intelligence Machine Learning Programming Python OOP Learning in Public</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79e5d150a0bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python File Handling & Exception Handling: Working With Real-World Data]]></title>
            <link>https://sonaliballa.medium.com/python-file-handling-exception-handling-working-with-real-world-data-ac09e7cacc8f?source=rss-33ceab3e2a99------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac09e7cacc8f</guid>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[python-file-handling]]></category>
            <category><![CDATA[exception-handling-python]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[SONALI BALLA]]></dc:creator>
            <pubDate>Mon, 28 Sep 2026 09:14:38 GMT</pubDate>
            <atom:updated>2026-09-28T09:14:38.195Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yiE22zGY_Dk3J5BqOeQiwg.png" /></figure><p><em>Day 6 of my Generative AI Learning Journey</em></p><p>So far, I’ve learned how to:</p><ul><li>Store and organize data</li><li>Make decisions</li><li>Repeat tasks</li><li>Create reusable functions</li><li>Work with Python data structures</li></ul><p>But real-world applications don’t always get perfect data.</p><p>Sometimes we need to:</p><p>📄 Read information from files<br>💾 Save information to files<br>⚠️ Handle unexpected errors<br>🔌 Work with external data and APIs<br>🤖 Process AI-generated responses</p><p>That’s where <strong>File Handling and Exception Handling</strong> become important.</p><p>Today, I’m revisiting both concepts and connecting them to my Gen AI journey.</p><h4>1. What Is File Handling?</h4><p>File handling allows Python programs to <strong>create, read, write, and modify files</strong>.</p><p>For example, suppose I have a file called:</p><pre>topics.txt</pre><p>containing:</p><pre>Python<br>Machine Learning<br>Deep Learning<br>Generative AI</pre><p>Instead of manually opening the file, I can use Python.</p><h4>2. Opening a File</h4><p>Python provides the open() function.</p><pre>file = open(&quot;topics.txt&quot;, &quot;r&quot;)</pre><p>Here:</p><ul><li>&quot;topics.txt&quot; → file name</li><li>&quot;r&quot; → read mode</li></ul><p>Common file modes include:</p><p>ModePurposerReadwWriteaAppendxCreate</p><h4>3. Reading a File</h4><p>We can read the entire file using read().</p><pre>file = open(&quot;topics.txt&quot;, &quot;r&quot;)</pre><pre>content = file.read()</pre><pre>print(content)</pre><pre>file.close()</pre><p>Output:</p><pre>Python<br>Machine Learning<br>Deep Learning<br>Generative AI</pre><p>The close() method closes the file after we&#39;re finished.</p><p>But there’s a better and safer way to work with files.</p><h4>4. Using with open()</h4><p>Instead of manually opening and closing the file, we can use a with statement.</p><pre>with open(&quot;topics.txt&quot;, &quot;r&quot;) as file:<br>    content = file.read()</pre><pre>print(content)</pre><p>Python automatically handles closing the file.</p><p>This is the approach I would prefer in most situations.</p><h4>5. Reading Line by Line</h4><p>Sometimes we don’t want the entire file at once.</p><p>We can process it line by line:</p><pre>with open(&quot;topics.txt&quot;, &quot;r&quot;) as file:</pre><pre>    for line in file:<br>        print(line.strip())</pre><p>This can be useful when working with larger files because we can process information incrementally rather than loading everything into memory at once.</p><h4>6. Writing to a File</h4><p>We can also create or overwrite a file using &quot;w&quot; mode.</p><pre>with open(&quot;learning.txt&quot;, &quot;w&quot;) as file:<br>    file.write(&quot;Python\n&quot;)<br>    file.write(&quot;Machine Learning\n&quot;)<br>    file.write(&quot;Generative AI\n&quot;)</pre><p>The file will contain:</p><pre>Python<br>Machine Learning<br>Generative AI</pre><p>⚠️ One important thing to remember:</p><p>&quot;w&quot; mode can <strong>overwrite existing content</strong>.</p><p>So we need to use it carefully.</p><h4>7. Appending to a File</h4><p>If I want to add new information without deleting existing content, I can use &quot;a&quot; mode.</p><pre>with open(&quot;learning.txt&quot;, &quot;a&quot;) as file:<br>    file.write(&quot;Transformers\n&quot;)</pre><p>Now the new topic is added to the end of the file.</p><p>This can be useful for things such as logs, notes, or continuously adding information.</p><h4>8. Working With JSON</h4><p>When moving toward AI applications, I will frequently encounter structured data.</p><p>One common format is <strong>JSON</strong>.</p><p>Example:</p><pre>{<br>    &quot;name&quot;: &quot;Sonali&quot;,<br>    &quot;role&quot;: &quot;Gen AI&quot;,<br>    &quot;skill&quot;: &quot;Python&quot;<br>}</pre><p>Python provides the built-in json module for working with JSON.</p><pre>import json</pre><pre>data = {<br>    &quot;name&quot;: &quot;Sonali&quot;,<br>    &quot;role&quot;: &quot;Gen AI&quot;,<br>    &quot;skill&quot;: &quot;Python&quot;<br>}</pre><pre>with open(&quot;profile.json&quot;, &quot;w&quot;) as file:<br>    json.dump(data, file, indent=4)</pre><p>Now Python has saved the dictionary as a JSON file.</p><p>We can read it again:</p><pre>with open(&quot;profile.json&quot;, &quot;r&quot;) as file:<br>    data = json.load(file)</pre><pre>print(data)</pre><p>JSON is especially useful when applications exchange structured information through APIs.</p><h4>9. What Is Exception Handling?</h4><p>Now let’s talk about something every programmer eventually encounters:</p><p><strong>Errors.</strong></p><p>Consider:</p><pre>number = int(input(&quot;Enter a number: &quot;))</pre><p>What happens if the user enters:</p><pre>hello</pre><p>Python can’t convert &quot;hello&quot; into an integer, so an exception occurs.</p><p>Instead of allowing the program to crash, we can handle the error.</p><h4>10. try and except</h4><p>The basic structure is:</p><pre>try:<br>    # code that might cause an error</pre><pre>except:<br>    # code to handle the error</pre><p>Example:</p><pre>try:<br>    number = int(input(&quot;Enter a number: &quot;))<br>    print(number)</pre><pre>except:<br>    print(&quot;Please enter a valid number.&quot;)</pre><p>If the user enters:</p><pre>hello</pre><p>we get:</p><pre>Please enter a valid number.</pre><p>The program handles the unexpected input instead of crashing.</p><h4>11. Handling Specific Exceptions</h4><p>It’s generally better to catch the specific exception we expect.</p><p>For example:</p><pre>try:<br>    number = int(input(&quot;Enter a number: &quot;))</pre><pre>except ValueError:<br>    print(&quot;Please enter a valid integer.&quot;)</pre><p>Here, we’re specifically handling a ValueError.</p><p>Some common exceptions include:</p><pre>ValueError<br>TypeError<br>FileNotFoundError<br>KeyError<br>IndexError<br>ZeroDivisionError</pre><p>Understanding these helps us debug Python programs more effectively.</p><h4>12. else</h4><p>Python also provides an else block.</p><p>It runs when no exception occurs.</p><pre>try:<br>    number = int(input(&quot;Enter a number: &quot;))</pre><pre>except ValueError:<br>    print(&quot;Invalid number.&quot;)</pre><pre>else:<br>    print(f&quot;You entered {number}.&quot;)</pre><p>So the flow is:</p><pre>try<br> ↓<br>Did an error occur?<br> ↓<br>Yes → except<br> ↓<br>No → else</pre><h4>13. finally</h4><p>The finally block runs whether an exception occurs or not.</p><pre>try:<br>    number = int(input(&quot;Enter a number: &quot;))</pre><pre>except ValueError:<br>    print(&quot;Invalid input.&quot;)</pre><pre>finally:<br>    print(&quot;Program finished.&quot;)</pre><p>This is useful when we have cleanup operations that should happen regardless of whether the operation succeeded.</p><h4>14. A Practical Example</h4><p>Let’s combine input and exception handling.</p><pre>while True:</pre><pre>    try:<br>        age = int(input(&quot;Enter your age: &quot;))<br>        print(f&quot;Your age is {age}.&quot;)<br>        break</pre><pre>    except ValueError:<br>        print(&quot;Please enter a valid number.&quot;)</pre><p>If the user enters:</p><pre>abc</pre><p>the program doesn’t immediately stop.</p><p>It asks again.</p><p>Once a valid number is entered, the loop ends.</p><p>This combines concepts I’ve already learned:</p><p><strong>Loop + Input + Exception Handling</strong></p><h4>15. Why Exception Handling Matters in Gen AI</h4><p>This is where the concept becomes particularly relevant to my Gen AI journey.</p><p>Imagine an application that sends a request to an AI model.</p><p>Many things could potentially go wrong:</p><pre>User Input<br>    ↓<br>Application<br>    ↓<br>AI API<br>    ↓<br>Model<br>    ↓<br>Response</pre><p>Possible problems could include:</p><ul><li>Invalid input</li><li>Missing data</li><li>Network problems</li><li>API errors</li><li>Invalid responses</li><li>Rate limits</li><li>Unexpected output</li></ul><p>A robust application shouldn’t simply crash whenever something unexpected happens.</p><p>We can use exception handling around operations that may fail.</p><p>For example, conceptually:</p><pre>try:<br>    response = model.generate(prompt)<br>    print(response)</pre><pre>except Exception as e:<br>    print(&quot;Something went wrong:&quot;, e)</pre><p>In real applications, we’d usually handle specific expected errors rather than relying only on a broad Exception handler.</p><h4>16. File Handling + Gen AI</h4><p>Another important connection is <strong>working with documents</strong>.</p><p>Imagine a Gen AI application that needs to process:</p><pre>PDF<br>TXT<br>CSV<br>JSON<br>Documents</pre><p>A simplified workflow could look like:</p><pre>Document<br>    ↓<br>Read File<br>    ↓<br>Extract Text<br>    ↓<br>Clean Text<br>    ↓<br>Split Text<br>    ↓<br>Create Embeddings<br>    ↓<br>Store / Retrieve<br>    ↓<br>LLM<br>    ↓<br>Generate Response</pre><p>This becomes particularly relevant later when I learn about <strong>RAG — Retrieval-Augmented Generation</strong>.</p><p>So today’s basic file-handling concepts are actually connected to topics I’ll encounter much later in my Gen AI journey.</p><h4>17. Mini Practice Challenge</h4><p>Here’s today’s challenge.</p><p>Create a program that:</p><ol><li>Asks the user for a file name.</li><li>Tries to open the file.</li><li>Prints its contents.</li><li>Handles the situation where the file doesn’t exist.</li></ol><p>Try solving it yourself first.</p><p>The key exception you’ll probably need is:</p><pre>FileNotFoundError</pre><p>A simple structure would be:</p><pre>try:<br>    # open and read file</pre><pre>except FileNotFoundError:<br>    # handle missing file</pre><p>Can you complete it?</p><h4>What I Learned Today</h4><p>Today I revised:</p><p>✅ Opening files<br>✅ Reading files<br>✅ Writing files<br>✅ Appending to files<br>✅ with open()<br>✅ JSON files<br>✅ try<br>✅ except<br>✅ else<br>✅ finally<br>✅ Common Python exceptions</p><h4>My Gen AI Journey</h4><p>So far:</p><p><strong>Day 1</strong> → Introduction to Python for Gen AI<br><strong>Day 2</strong> → Variables, Data Types, Operators, Input &amp; Output<br><strong>Day 3</strong> → Conditional Statements &amp; Loops<br><strong>Day 4</strong> → Functions<br><strong>Day 5</strong> → Python Data Structures<br><strong>Day 6</strong> → File Handling &amp; Exception Handling ✅</p><p>Next:</p><p><strong>Day 7 → Object-Oriented Programming (OOP) in Python</strong></p><p>I’m getting closer to the concepts I’ll need when I start working with larger Python libraries and AI frameworks.</p><h4>Your Turn</h4><p>Here’s today’s question:</p><p><strong>When you’re learning Python, which do you find more challenging — understanding errors or fixing them?</strong></p><p>And if you’ve ever encountered a Python error that took you a long time to solve, share it below.</p><p>Someone else learning Python might have faced the exact same problem!</p><h4>Tags</h4><p>Python GenerativeAI GenAI ArtificialIntelligence MachineLearning PythonProgramming LearningInPublic AI</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac09e7cacc8f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Data Structures: How I Organize Data for AI]]></title>
            <link>https://sonaliballa.medium.com/python-data-structures-how-i-organize-data-for-ai-3f579c74c0b1?source=rss-33ceab3e2a99------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f579c74c0b1</guid>
            <category><![CDATA[lists-in-python]]></category>
            <category><![CDATA[sets-in-python]]></category>
            <category><![CDATA[tuples-in-python]]></category>
            <category><![CDATA[python-data-structures]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[SONALI BALLA]]></dc:creator>
            <pubDate>Sun, 27 Sep 2026 14:34:12 GMT</pubDate>
            <atom:updated>2026-09-27T14:35:19.491Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YQsHD82K78HOYT5EPP6qUw.png" /></figure><p><em>Day 5 of my Generative AI Learning Journey</em></p><p>A program can process information only if we know how to <strong>store and organize that information</strong>.</p><p>Imagine I have:</p><ul><li>A list of AI topics</li><li>A collection of unique skills</li><li>Information about a user</li><li>Multiple prompts</li><li>A dataset containing thousands of records</li></ul><p>How should I store all this information in Python?</p><p>That’s where <strong>data structures</strong> come in.</p><p>Today, I’m revisiting some of the most important Python data structures:</p><ul><li>Lists</li><li>Tuples</li><li>Sets</li><li>Dictionaries</li><li>List comprehensions</li><li>Dictionary comprehensions</li></ul><p>And I’m also looking at how these concepts connect to <strong>AI and Gen AI applications</strong>.</p><h4>What Are Data Structures?</h4><p>A data structure is a way of <strong>organizing and storing data</strong> so that we can work with it efficiently.</p><p>Python provides several built-in data structures.</p><figure><img alt="Python Data Structures Comparision" src="https://cdn-images-1.medium.com/max/1024/1*uhLO-8AOd7WsQguWfNBbqA.png" /></figure><p>&gt; Sets are unordered collections in the traditional sense; don’t rely on positional ordering.</p><p>&gt; Dictionaries preserve insertion order in modern Python.</p><p>Let’s explore them one by one.</p><h4>1. Lists</h4><p>A list is one of the most commonly used Python data structures.</p><p>Lists allow us to store multiple values in a single variable.</p><pre>topics = [&quot;Python&quot;, &quot;Machine Learning&quot;, &quot;Deep Learning&quot;, &quot;Gen AI&quot;]</pre><pre>print(topics)</pre><p>Output:</p><pre>[&#39;Python&#39;, &#39;Machine Learning&#39;, &#39;Deep Learning&#39;, &#39;Gen AI&#39;]</pre><p>Lists can contain different data types:</p><pre>data = [&quot;Python&quot;, 10, 3.14, True]</pre><h4>Accessing List Elements</h4><p>Python uses <strong>zero-based indexing</strong>.</p><pre>topics = [&quot;Python&quot;, &quot;ML&quot;, &quot;DL&quot;, &quot;Gen AI&quot;]</pre><pre>print(topics[0])<br>print(topics[1])<br>print(topics[3])</pre><p>Output:</p><pre>Python<br>ML<br>Gen AI</pre><p>The first element has index 0.</p><pre>Python → 0<br>ML     → 1<br>DL     → 2<br>Gen AI → 3</pre><h4>Modifying Lists</h4><p>Lists are mutable, which means we can change their contents.</p><pre>topics = [&quot;Python&quot;, &quot;ML&quot;, &quot;DL&quot;]</pre><pre>topics[1] = &quot;Machine Learning&quot;</pre><pre>print(topics)</pre><p>Output:</p><pre>[&#39;Python&#39;, &#39;Machine Learning&#39;, &#39;DL&#39;]</pre><p>We can also add elements:</p><pre>topics.append(&quot;Gen AI&quot;)</pre><p>Remove elements:</p><pre>topics.remove(&quot;DL&quot;)</pre><p>And insert elements:</p><pre>topics.insert(1, &quot;SQL&quot;)</pre><h4>Why Lists Matter in AI</h4><p>Lists are everywhere in AI applications.</p><p>For example:</p><pre>prompts = [<br>    &quot;Explain Python&quot;,<br>    &quot;Explain Machine Learning&quot;,<br>    &quot;Explain Generative AI&quot;<br>]</pre><p>We could then process each prompt using a loop:</p><pre>for prompt in prompts:<br>    print(prompt)</pre><p>Later, the same idea can be used when processing multiple inputs, documents, questions, or model outputs.</p><h4>2. Tuples</h4><p>A tuple is similar to a list, but it is <strong>immutable</strong>.</p><pre>coordinates = (10, 20)</pre><p>Once created, we cannot modify individual elements.</p><pre>coordinates[0] = 50</pre><p>This will produce an error because tuples cannot be changed this way.</p><p>Tuples are useful when we want to represent a collection of values that shouldn’t be modified.</p><p>For example:</p><pre>model_info = (&quot;GPT&quot;, &quot;LLM&quot;, 2026)</pre><h4>List vs Tuple</h4><p>A simple way to remember:</p><pre>List   → Can change<br>Tuple  → Cannot change</pre><p>Example:</p><pre>skills = [&quot;Python&quot;, &quot;SQL&quot;]<br>skills.append(&quot;ML&quot;)</pre><p>This works.</p><p>But:</p><pre>skills = (&quot;Python&quot;, &quot;SQL&quot;)<br>skills.append(&quot;ML&quot;)</pre><p>This doesn’t work because tuples don’t support list-style modification.</p><h4>3. Sets</h4><p>A set is a collection of <strong>unique elements</strong>.</p><pre>skills = {&quot;Python&quot;, &quot;SQL&quot;, &quot;Python&quot;, &quot;ML&quot;}</pre><pre>print(skills)</pre><p>The duplicate &quot;Python&quot; is removed.</p><p>The exact display order of a set should not be relied upon.</p><p>Sets are useful when we care about uniqueness.</p><p>For example:</p><pre>skills = [&quot;Python&quot;, &quot;Python&quot;, &quot;SQL&quot;, &quot;ML&quot;, &quot;SQL&quot;]</pre><pre>unique_skills = set(skills)</pre><pre>print(unique_skills)</pre><p>Now we have only unique values.</p><h4>Why Sets Can Be Useful in AI</h4><p>Imagine extracting keywords from multiple documents.</p><p>You might get:</p><pre>Python<br>AI<br>Python<br>ML<br>AI<br>Gen AI</pre><p>If I only want the unique keywords:</p><pre>keywords = {&quot;Python&quot;, &quot;AI&quot;, &quot;ML&quot;, &quot;Gen AI&quot;}</pre><p>A set is useful for this type of operation.</p><h4>4. Dictionaries</h4><p>Now we come to one of the most useful Python data structures for application development:</p><p><strong>Dictionaries.</strong></p><p>A dictionary stores data as:</p><pre>key → value</pre><p>Example:</p><pre>student = {<br>    &quot;name&quot;: &quot;Sonali&quot;,<br>    &quot;skill&quot;: &quot;Python&quot;,<br>    &quot;goal&quot;: &quot;Gen AI&quot;<br>}</pre><p>We can access a value using its key:</p><pre>print(student[&quot;name&quot;])</pre><p>Output:</p><pre>Sonali</pre><h4>Adding and Updating Dictionary Values</h4><p>We can add a new key-value pair:</p><pre>student[&quot;experience&quot;] = &quot;Fresher&quot;</pre><p>We can update an existing value:</p><pre>student[&quot;skill&quot;] = &quot;Generative AI&quot;</pre><p>Now:</p><pre>print(student)</pre><h4>Why Dictionaries Matter in Gen AI</h4><p>Dictionaries are extremely useful when representing structured information.</p><p>For example, imagine storing information about an AI model:</p><pre>model = {<br>    &quot;name&quot;: &quot;MyModel&quot;,<br>    &quot;type&quot;: &quot;LLM&quot;,<br>    &quot;language&quot;: &quot;Python&quot;,<br>    &quot;temperature&quot;: 0.7<br>}</pre><p>Or user information:</p><pre>user = {<br>    &quot;name&quot;: &quot;Sonali&quot;,<br>    &quot;question&quot;: &quot;What is RAG?&quot;,<br>    &quot;language&quot;: &quot;English&quot;<br>}</pre><p>Or configuration information:</p><pre>config = {<br>    &quot;model&quot;: &quot;my-model&quot;,<br>    &quot;temperature&quot;: 0.7,<br>    &quot;max_tokens&quot;: 500<br>}</pre><p>This key-value structure appears frequently in Python applications and APIs.</p><h4>5. Nested Data Structures</h4><p>Python data structures can be combined.</p><p>For example, we can have a list of dictionaries:</p><pre>students = [<br>    {<br>        &quot;name&quot;: &quot;A&quot;,<br>        &quot;skill&quot;: &quot;Python&quot;<br>    },<br>    {<br>        &quot;name&quot;: &quot;B&quot;,<br>        &quot;skill&quot;: &quot;Machine Learning&quot;<br>    },<br>    {<br>        &quot;name&quot;: &quot;C&quot;,<br>        &quot;skill&quot;: &quot;Gen AI&quot;<br>    }<br>]</pre><p>Now we can access individual information:</p><pre>print(students[0][&quot;name&quot;])</pre><p>Output:</p><pre>A</pre><p>This type of structure is particularly useful when working with structured records.</p><h4>6. List Comprehension</h4><p>Python provides a concise way to create lists called <strong>list comprehension</strong>.</p><p>Instead of:</p><pre>numbers = []</pre><pre>for i in range(1, 6):<br>    numbers.append(i * 2)</pre><pre>print(numbers)</pre><p>We can write:</p><pre>numbers = [i * 2 for i in range(1, 6)]</pre><pre>print(numbers)</pre><p>Output:</p><pre>[2, 4, 6, 8, 10]</pre><p>The general structure is:</p><pre>[expression for item in iterable]</pre><h4>List Comprehension With Conditions</h4><p>We can also add a condition.</p><pre>numbers = [1, 2, 3, 4, 5, 6]</pre><pre>even_numbers = [x for x in numbers if x % 2 == 0]</pre><pre>print(even_numbers)</pre><p>Output:</p><pre>[2, 4, 6]</pre><p>This can make simple data-processing operations concise.</p><h4>7. Dictionary Comprehension</h4><p>Python also supports dictionary comprehensions.</p><p>For example:</p><pre>numbers = [1, 2, 3, 4, 5]</pre><pre>squares = {x: x * x for x in numbers}</pre><pre>print(squares)</pre><p>Output:</p><pre>{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}</pre><p>This is useful when creating dictionaries programmatically.</p><h4>8. Choosing the Right Data Structure</h4><p>One thing I learned while revisiting these concepts is that there isn’t one “best” data structure.</p><p>It depends on what I need.</p><h4>Need an ordered collection that can change?</h4><p>Use a <strong>list</strong>.</p><pre>topics = [&quot;Python&quot;, &quot;ML&quot;, &quot;DL&quot;]</pre><h4>Need a collection that shouldn’t change?</h4><p>Use a <strong>tuple</strong>.</p><pre>coordinates = (10, 20)</pre><h4>Need unique values?</h4><p>Use a <strong>set</strong>.</p><pre>skills = {&quot;Python&quot;, &quot;SQL&quot;, &quot;ML&quot;}</pre><h4>Need key-value information?</h4><p>Use a <strong>dictionary</strong>.</p><pre>user = {<br>    &quot;name&quot;: &quot;Sonali&quot;,<br>    &quot;skill&quot;: &quot;Gen AI&quot;<br>}</pre><h4>9. A Small Gen AI-Style Example</h4><p>Let’s imagine a simple application that stores information about a user’s Gen AI learning journey.</p><pre>user = {<br>    &quot;name&quot;: &quot;Sonali&quot;,<br>    &quot;goal&quot;: &quot;Gen AI Engineer&quot;,<br>    &quot;skills&quot;: [<br>        &quot;Python&quot;,<br>        &quot;SQL&quot;,<br>        &quot;Machine Learning&quot;,<br>        &quot;Deep Learning&quot;<br>    ],<br>    &quot;current_topic&quot;: &quot;Transformers&quot;<br>}</pre><p>Now we can access the information:</p><pre>print(user[&quot;name&quot;])<br>print(user[&quot;goal&quot;])<br>print(user[&quot;current_topic&quot;])</pre><p>We can also loop through the skills:</p><pre>for skill in user[&quot;skills&quot;]:<br>    print(skill)</pre><p>This small example combines:</p><ul><li>Dictionary</li><li>List</li><li>String</li><li>Loop</li></ul><p>And this kind of combination is much closer to the type of data structures we encounter in real applications.</p><h4>Mini Challenge</h4><p>Try this before looking at the solution.</p><h4>Challenge:</h4><p>Create a dictionary containing:</p><ul><li>Your name</li><li>Your target role</li><li>Your current skills</li><li>Your current Gen AI topic</li></ul><p>Then:</p><ol><li>Print your target role.</li><li>Print each skill using a loop.</li><li>Add a new skill.</li><li>Update your current topic.</li></ol><p>For example:</p><pre>profile = {<br>    &quot;name&quot;: &quot;Your Name&quot;,<br>    &quot;target_role&quot;: &quot;Gen AI Engineer&quot;,<br>    &quot;skills&quot;: [&quot;Python&quot;, &quot;SQL&quot;, &quot;ML&quot;],<br>    &quot;current_topic&quot;: &quot;Transformers&quot;<br>}</pre><p>Can you complete the remaining steps?</p><h4>What I Learned Today</h4><p>Today I revised:</p><p>✅ Lists<br>✅ Tuples<br>✅ Sets<br>✅ Dictionaries<br>✅ Nested data structures<br>✅ List comprehensions<br>✅ Dictionary comprehensions</p><p>But the biggest takeaway for me is:</p><blockquote><strong><em>Choosing the right data structure can make our code easier to understand, manipulate, and maintain.</em></strong></blockquote><p>And when I move toward AI and Gen AI, I’ll be working with different kinds of data constantly.</p><h4>My Gen AI Journey</h4><p>So far:</p><p><strong>Day 1</strong> → Introduction to Python for Gen AI<br><strong>Day 2</strong> → Variables, Data Types, Operators, Input &amp; Output<br><strong>Day 3</strong> → Conditional Statements &amp; Loops<br><strong>Day 4</strong> → Functions<br><strong>Day 5</strong> → Python Data Structures ✅</p><p>Next:</p><p><strong>Day 6 → File Handling &amp; Exception Handling</strong></p><p>I’m slowly building the Python foundation I need before moving deeper into Machine Learning, Deep Learning, Transformers, LLMs, and Generative AI.</p><h4>Your Turn</h4><p>Here’s a question for anyone learning Python:</p><p><strong>Which Python data structure do you use the most — List, Tuple, Set, or Dictionary?</strong></p><p>And if you’re learning Python for AI/ML, <strong>what are you currently working on?</strong></p><p>Share it in the comments. I’d love to learn from other people on the same journey. 👇</p><h3>Tags</h3><p>Python GenerativeAI GenAI ArtificialIntelligence MachineLearning PythonProgramming LearningInPublic DataScience</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f579c74c0b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Functions: The Building Blocks of Reusable Code]]></title>
            <link>https://sonaliballa.medium.com/python-functions-the-building-blocks-of-reusable-code-41b10099953d?source=rss-33ceab3e2a99------2</link>
            <guid isPermaLink="false">https://medium.com/p/41b10099953d</guid>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python-functions]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[SONALI BALLA]]></dc:creator>
            <pubDate>Sat, 26 Sep 2026 11:42:36 GMT</pubDate>
            <atom:updated>2026-09-26T11:42:36.339Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KNcLZs9CWbN-AeXMv9gOqQ.png" /></figure><p><em>Day 4 of my Generative AI Learning Journey</em></p><p>Imagine writing the same 20 lines of code every time you want to perform a particular task.</p><p>It would quickly become difficult to maintain.</p><p>Instead, what if I could write that logic <strong>once</strong> and reuse it whenever I need it?</p><p>That’s exactly what <strong>functions</strong> help us do.</p><p>Today, I’m revisiting one of the most important concepts in Python:</p><blockquote><strong><em>Functions allow us to organize code into reusable blocks.</em></strong></blockquote><p>And as I move toward Machine Learning and Generative AI, this concept becomes even more important because AI applications are usually built by combining many small, reusable functions.</p><h4>What is a Function?</h4><p>A function is a reusable block of code designed to perform a specific task.</p><p>The basic syntax is:</p><pre>def function_name():<br>    # code</pre><p>For example:</p><pre>def greet():<br>    print(&quot;Hello, welcome to my Gen AI journey!&quot;)</pre><p>Defining a function doesn’t execute it.</p><p>We need to <strong>call</strong> the function:</p><pre>greet()</pre><p>Output:</p><pre>Hello, welcome to my Gen AI journey!</pre><h4>Why Do We Need Functions?</h4><p>Without functions, we might write:</p><pre>print(&quot;Hello Sonali&quot;)<br>print(&quot;Hello Sonali&quot;)<br>print(&quot;Hello Sonali&quot;)</pre><p>Instead, we can write:</p><pre>def greet():<br>    print(&quot;Hello Sonali&quot;)</pre><pre>greet()<br>greet()<br>greet()</pre><p>Now the same logic can be reused.</p><p>This gives us several benefits:</p><ul><li>Reusability</li><li>Cleaner code</li><li>Easier debugging</li><li>Better organization</li><li>Easier maintenance</li><li>Less repetitive code</li></ul><h4>Functions With Parameters</h4><p>What if I don’t want my function to always greet the same person?</p><p>We can pass information into a function using <strong>parameters</strong>.</p><pre>def greet(name):<br>    print(f&quot;Hello {name}!&quot;)</pre><p>Now I can call it with different values:</p><pre>greet(&quot;Sonali&quot;)<br>greet(&quot;Python&quot;)<br>greet(&quot;Gen AI&quot;)</pre><p>Output:</p><pre>Hello Sonali!<br>Hello Python!<br>Hello Gen AI!</pre><p>The function becomes much more flexible.</p><h4>Parameters vs Arguments</h4><p>These two terms are often confused.</p><p>In:</p><pre>def greet(name):<br>    print(f&quot;Hello {name}&quot;)</pre><p>name is a <strong>parameter</strong>.</p><p>When we call:</p><pre>greet(&quot;Sonali&quot;)</pre><p>&quot;Sonali&quot; is an <strong>argument</strong>.</p><p>A simple way to remember it:</p><blockquote><strong><em>Parameter → placeholder inside the function</em></strong><em><br></em><strong><em>Argument → actual value passed to the function</em></strong></blockquote><h4>Returning Values From a Function</h4><p>A function doesn’t always need to print something.</p><p>Sometimes we want it to <strong>return a result</strong>.</p><p>For example:</p><pre>def add(a, b):<br>    return a + b</pre><p>Now:</p><pre>result = add(10, 20)</pre><pre>print(result)</pre><p>Output:</p><pre>30</pre><p>The return statement sends a value back to the place where the function was called.</p><h4>print() vs return</h4><p>This is an important distinction.</p><h4>Using print()</h4><pre>def add(a, b):<br>    print(a + b)</pre><p>This displays the result.</p><h4>Using return</h4><pre>def add(a, b):<br>    return a + b</pre><p>This gives the result back so we can use it later.</p><p>For example:</p><pre>result = add(10, 20)</pre><pre>new_result = result * 2</pre><pre>print(new_result)</pre><p>Output:</p><pre>60</pre><p>Using return gives us more flexibility.</p><h4>Functions With Multiple Parameters</h4><p>A function can accept multiple parameters.</p><pre>def introduce(name, role, skill):<br>    print(f&quot;My name is {name}.&quot;)<br>    print(f&quot;I am preparing for a {role} role.&quot;)<br>    print(f&quot;I am learning {skill}.&quot;)</pre><p>Calling it:</p><pre>introduce(&quot;Sonali&quot;, &quot;Gen AI&quot;, &quot;Python&quot;)</pre><p>Output:</p><pre>My name is Sonali.<br>I am preparing for a Gen AI role.<br>I am learning Python.</pre><h4>Default Parameters</h4><p>We can also provide a default value.</p><pre>def greet(name=&quot;Developer&quot;):<br>    print(f&quot;Hello {name}!&quot;)</pre><p>If we provide a name:</p><pre>greet(&quot;Sonali&quot;)</pre><p>Output:</p><pre>Hello Sonali!</pre><p>If we don’t:</p><pre>greet()</pre><p>Output:</p><pre>Hello Developer!</pre><p>Default parameters are useful when we want a function to work even if a particular argument isn’t provided.</p><h4>Keyword Arguments</h4><p>Instead of relying on the order of arguments, we can specify their names.</p><pre>def profile(name, role, experience):<br>    print(name, role, experience)</pre><p>We can call it like this:</p><pre>profile(<br>    name=&quot;Sonali&quot;,<br>    role=&quot;Gen AI Developer&quot;,<br>    experience=&quot;Fresher&quot;<br>)</pre><p>This can make function calls easier to understand, especially when there are many parameters.</p><h4>*args</h4><p>Sometimes we don’t know how many positional arguments we’ll receive.</p><p>Python provides *args for this.</p><pre>def add_numbers(*numbers):<br>    total = 0</pre><pre>    for number in numbers:<br>        total += number</pre><pre>    return total</pre><p>Now we can pass different numbers of arguments:</p><pre>print(add_numbers(10, 20))<br>print(add_numbers(10, 20, 30))<br>print(add_numbers(1, 2, 3, 4, 5))</pre><p>Output:</p><pre>30<br>60<br>15</pre><h4>**kwargs</h4><p>Similarly, **kwargs allows us to accept multiple keyword arguments.</p><pre>def show_profile(**details):<br>    for key, value in details.items():<br>        print(f&quot;{key}: {value}&quot;)</pre><p>We can call:</p><pre>show_profile(<br>    name=&quot;Sonali&quot;,<br>    skill=&quot;Python&quot;,<br>    goal=&quot;Gen AI&quot;<br>)</pre><p>Output:</p><pre>name: Sonali<br>skill: Python<br>goal: Gen AI</pre><p>You don’t need to use *args and **kwargs everywhere, but understanding them is useful when working with Python libraries and frameworks.</p><h4>Lambda Functions</h4><p>Python also allows us to create small anonymous functions using lambda.</p><p>For example:</p><pre>square = lambda x: x * x</pre><pre>print(square(5))</pre><p>Output:</p><pre>25</pre><p>A lambda function is useful for short operations where defining a full function may be unnecessary.</p><p>For example:</p><pre>numbers = [1, 2, 3, 4, 5]</pre><pre>squares = list(map(lambda x: x * x, numbers))</pre><pre>print(squares)</pre><p>Output:</p><pre>[1, 4, 9, 16, 25]</pre><p>For larger or more complex logic, a normal def function is usually easier to read.</p><h4>Functions Can Call Other Functions</h4><p>Python functions can work together.</p><pre>def clean_text(text):<br>    return text.strip().lower()</pre><pre>def create_prompt(text):<br>    cleaned_text = clean_text(text)<br>    return f&quot;Explain this topic: {cleaned_text}&quot;</pre><pre>prompt = create_prompt(&quot;  GENERATIVE AI  &quot;)</pre><pre>print(prompt)</pre><p>Output:</p><pre>Explain this topic: generative ai</pre><p>This is a simple example of breaking a larger task into smaller pieces.</p><h4>Why Functions Matter in Gen AI</h4><p>This is where today’s topic becomes particularly interesting for me.</p><p>A Gen AI application may have many different tasks:</p><pre>User Input<br>     ↓<br>Validate Input<br>     ↓<br>Clean Text<br>     ↓<br>Create Prompt<br>     ↓<br>Call AI Model<br>     ↓<br>Process Response<br>     ↓<br>Display Response</pre><p>Instead of putting everything into one huge block of code, we can create separate functions:</p><pre>def validate_input():<br>    pass</pre><pre>def clean_text():<br>    pass</pre><pre>def create_prompt():<br>    pass</pre><pre>def call_model():<br>    pass</pre><pre>def process_response():<br>    pass</pre><p>Each function has a specific responsibility.</p><p>This makes the application easier to understand, test, modify, and reuse.</p><h4>Mini Practice Challenge</h4><p>Try solving this before looking at the solution.</p><h3>Challenge</h3><p>Create a function called calculate_average() that accepts three numbers and returns their average.</p><p>For example:</p><pre>result = calculate_average(80, 90, 70)</pre><pre>print(result)</pre><p>Expected output:</p><pre>80.0</pre><h4>My approach</h4><pre>def calculate_average(a, b, c):<br>    return (a + b + c) / 3</pre><p>Simple, but it reinforces an important idea:</p><p><strong>Input → Processing → Output</strong></p><p>And that pattern appears repeatedly in programming and AI applications.</p><h4>What I Learned Today</h4><p>Today I revised:</p><p>✅ What functions are<br>✅ Creating functions with def<br>✅ Parameters and arguments<br>✅ return<br>✅ Default parameters<br>✅ Keyword arguments<br>✅ *args<br>✅ **kwargs<br>✅ Lambda functions<br>✅ Functions calling other functions<br>✅ Using functions to structure AI applications</p><p>But my biggest takeaway is:</p><blockquote><strong><em>Good code isn’t just about making something work. It’s also about organizing the code so that it can be reused and maintained.</em></strong></blockquote><p>As I continue toward Gen AI, I expect functions to become one of the Python concepts I use constantly.</p><h4>My Gen AI Journey</h4><p>So far:</p><p><strong>Day 1</strong> → Introduction to Python for Gen AI<br><strong>Day 2</strong> → Variables, Data Types, Operators, Input &amp; Output<br><strong>Day 3</strong> → Conditional Statements &amp; Loops<br><strong>Day 4</strong> → Functions ✅</p><p>Next:</p><p><strong>Day 5 → Python Data Structures</strong></p><p>I’ll explore lists, tuples, sets, dictionaries, and comprehensions — concepts that become extremely useful when working with data and AI applications.</p><h4>Your Turn</h4><p>Here’s a small question for anyone learning Python:</p><p><strong>When you write Python programs, do you prefer creating many small functions or writing everything in one program? Why?</strong></p><p>I’m curious to know how others approach their Python code.</p><p>If you’re also learning Python for <strong>AI/ML/Gen AI</strong>, feel free to share where you are in your journey.</p><h4>Tags</h4><p>Python GenerativeAI GenAI ArtificialIntelligence MachineLearning PythonProgramming LearningInPublic Programming</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41b10099953d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Conditional Statements & Loops: Teaching Programs How to Think]]></title>
            <link>https://sonaliballa.medium.com/python-conditional-statements-loops-teaching-programs-how-to-think-07cfe1af5163?source=rss-33ceab3e2a99------2</link>
            <guid isPermaLink="false">https://medium.com/p/07cfe1af5163</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[loops-in-python]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[conditional-statements]]></category>
            <dc:creator><![CDATA[SONALI BALLA]]></dc:creator>
            <pubDate>Fri, 25 Sep 2026 08:03:21 GMT</pubDate>
            <atom:updated>2026-09-25T08:03:21.132Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UpYbKfuJeX_kAD9fdpqfZw.png" /></figure><p><em>Day 3 of my Generative AI Learning Journey</em></p><blockquote><strong><em>A program becomes useful when it can make decisions and repeat tasks.</em></strong></blockquote><p>So far in my Python journey, I’ve learned how to store information, work with different data types, take input, and display output.</p><p>But what if I want my program to <strong>make a decision?</strong></p><p>What if I want it to <strong>repeat an action 100 times without writing the same code 100 times?</strong></p><p>That’s where <strong>conditional statements and loops</strong> come in.</p><p>Today, I’m revisiting:</p><ul><li>if, elif, and else</li><li>Comparison operators</li><li>Logical operators</li><li>for loops</li><li>while loops</li><li>break</li><li>continue</li><li>Nested loops</li><li>Practical examples</li><li>How these concepts connect to Gen AI</li></ul><h4>1. Conditional Statements</h4><p>Conditional statements allow a program to make decisions based on a condition.</p><p>The basic structure is:</p><pre>if condition:<br>    # code to execute</pre><p>For example:</p><pre>age = 20</pre><pre>if age &gt;= 18:<br>    print(&quot;You are an adult.&quot;)</pre><p>The program checks the condition:</p><pre>Is age &gt;= 18?<br>       ↓<br>     True<br>       ↓<br>Execute the code</pre><p>This is one of the most basic forms of decision-making in programming.</p><h4>2. if, elif, and else</h4><p>When there are multiple possibilities, we can use elif and else.</p><pre>marks = 75</pre><pre>if marks &gt;= 90:<br>    print(&quot;Excellent&quot;)<br>elif marks &gt;= 60:<br>    print(&quot;Good&quot;)<br>else:<br>    print(&quot;Needs improvement&quot;)</pre><p>Output:</p><pre>Good</pre><p>The program evaluates the conditions from top to bottom.</p><p>This gives our programs the ability to respond differently depending on the situation.</p><h4>3. Comparison Operators</h4><p>Conditions often use comparison operators.</p><pre>==<br>!=<br>&gt;<br>&lt;<br>&gt;=<br>&lt;=</pre><p>Example:</p><pre>temperature = 35</pre><pre>if temperature &gt; 30:<br>    print(&quot;It&#39;s a hot day.&quot;)</pre><p>Here, Python checks whether:</p><pre>35 &gt; 30</pre><p>The result is True, so the message is printed.</p><h4>4. Combining Conditions</h4><p>We can combine multiple conditions using:</p><ul><li>and</li><li>or</li><li>not</li></ul><p>Example:</p><pre>age = 22<br>has_python_skill = True</pre><pre>if age &gt;= 18 and has_python_skill:<br>    print(&quot;You meet the requirements.&quot;)</pre><p>Both conditions must be true because we used and.</p><h4>5. Why Conditions Matter in AI Applications</h4><p>This is where I started seeing a connection between basic Python and AI.</p><p>Imagine an AI application receiving a user’s question.</p><p>We might want to handle different types of requests differently:</p><pre>question = &quot;What is Python?&quot;</pre><pre>if &quot;Python&quot; in question:<br>    print(&quot;This question is related to Python.&quot;)<br>else:<br>    print(&quot;This question is about something else.&quot;)</pre><p>This isn’t an AI model by itself.</p><p>But it shows how <strong>Python logic can be used around an AI system</strong> to control what happens based on input.</p><p>As I move further into Gen AI, I’ll see much more sophisticated versions of this kind of application logic.</p><h4>6. What Are Loops?</h4><p>A loop allows us to execute a block of code repeatedly.</p><p>Instead of writing:</p><pre>print(&quot;Hello&quot;)<br>print(&quot;Hello&quot;)<br>print(&quot;Hello&quot;)<br>print(&quot;Hello&quot;)<br>print(&quot;Hello&quot;)</pre><p>we can write:</p><pre>for i in range(5):<br>    print(&quot;Hello&quot;)</pre><p>Much cleaner!</p><p>The loop repeats the operation automatically.</p><h4>7. for Loop</h4><p>A for loop is commonly used when we want to iterate over a sequence.</p><p>For example:</p><pre>topics = [&quot;Python&quot;, &quot;Machine Learning&quot;, &quot;Deep Learning&quot;, &quot;Gen AI&quot;]</pre><pre>for topic in topics:<br>    print(topic)</pre><p>Output:</p><pre>Python<br>Machine Learning<br>Deep Learning<br>Gen AI</pre><p>Here, the loop goes through each item in the list.</p><h4>8. Using range()</h4><p>We can use range() to generate a sequence of numbers.</p><pre>for i in range(5):<br>    print(i)</pre><p>Output:</p><pre>0<br>1<br>2<br>3<br>4</pre><p>Notice that range(5) starts from 0 and stops before 5.</p><p>We can also specify a starting point:</p><pre>for i in range(1, 6):<br>    print(i)</pre><p>Output:</p><pre>1<br>2<br>3<br>4<br>5</pre><h4>9. while Loop</h4><p>A while loop keeps running as long as a condition remains true.</p><pre>count = 1</pre><pre>while count &lt;= 5:<br>    print(count)<br>    count += 1</pre><p>Output:</p><pre>1<br>2<br>3<br>4<br>5</pre><p>The important thing with a while loop is making sure the condition eventually becomes false.</p><p>Otherwise, we can accidentally create an <strong>infinite loop</strong>.</p><h4>10. break</h4><p>Sometimes we want to stop a loop before it finishes.</p><p>That’s where break is useful.</p><pre>for i in range(10):<br>    if i == 5:<br>        break</pre><pre>    print(i)</pre><p>Output:</p><pre>0<br>1<br>2<br>3<br>4</pre><p>When i becomes 5, the loop stops.</p><h4>11. continue</h4><p>continue works differently.</p><p>It skips the current iteration and moves to the next one.</p><pre>for i in range(5):<br>    if i == 2:<br>        continue</pre><pre>    print(i)</pre><p>Output:</p><pre>0<br>1<br>3<br>4</pre><p>The value 2 is skipped.</p><h4>12. Nested Loops</h4><p>A loop inside another loop is called a nested loop.</p><p>For example:</p><pre>for i in range(3):<br>    for j in range(2):<br>        print(i, j)</pre><p>Nested loops can be useful when working with multiple dimensions of data or when processing combinations of values.</p><p>However, it’s important to use them carefully because nested loops can become expensive when working with large datasets.</p><h4>13. A Small Practical Example</h4><p>Let’s combine conditions and loops.</p><p>Suppose I have a list of scores:</p><pre>scores = [45, 78, 92, 56, 88]</pre><pre>for score in scores:</pre><pre>    if score &gt;= 90:<br>        print(score, &quot;Excellent&quot;)</pre><pre>    elif score &gt;= 60:<br>        print(score, &quot;Good&quot;)</pre><pre>    else:<br>        print(score, &quot;Needs improvement&quot;)</pre><p>Output:</p><pre>45 Needs improvement<br>78 Good<br>92 Excellent<br>56 Needs improvement<br>88 Good</pre><p>Here, I’m using both:</p><p><strong>Loop + Condition</strong></p><pre>List<br> ↓<br>Loop through each value<br> ↓<br>Check condition<br> ↓<br>Print appropriate result</pre><p>This pattern appears everywhere in programming.</p><h3>14. Connecting Loops to Gen AI</h3><p>Here’s a simple conceptual example.</p><p>Suppose we have multiple questions that we want to send to an AI system:</p><pre>questions = [<br>    &quot;What is Python?&quot;,<br>    &quot;What is machine learning?&quot;,<br>    &quot;What is Generative AI?&quot;<br>]</pre><pre>for question in questions:<br>    print(f&quot;Processing: {question}&quot;)</pre><p>Output:</p><pre>Processing: What is Python?<br>Processing: What is machine learning?<br>Processing: What is Generative AI?</pre><p>Later, instead of simply printing the questions, an AI application could process each question using a model.</p><p>Conceptually:</p><pre>Questions<br>    ↓<br>Loop<br>    ↓<br>Send each question to AI<br>    ↓<br>Receive response<br>    ↓<br>Process/store response</pre><p>This is one reason basic programming concepts remain important even when working with powerful AI models.</p><h4>15. A Mini Challenge for You</h4><p>Before looking at the answer, try this yourself.</p><h4>Challenge:</h4><p>Write a Python program that:</p><ol><li>Takes a number from the user.</li><li>Checks whether it is positive, negative, or zero.</li><li>If it’s positive, print all numbers from 1 to that number.</li></ol><p>For example:</p><pre>Enter a number: 5</pre><pre>Positive number<br>1<br>2<br>3<br>4<br>5</pre><p><strong>Can you solve it without looking at the answer?</strong></p><p>That’s the kind of small practice I’m using while revisiting Python.</p><h4>What I Learned Today</h4><p>Today I revised:</p><p>✅ if<br>✅ elif<br>✅ else<br>✅ Comparison operators<br>✅ Logical operators<br>✅ for loops<br>✅ while loops<br>✅ range()<br>✅ break<br>✅ continue<br>✅ Nested loops</p><p>But the bigger takeaway for me is:</p><blockquote><strong><em>Programming isn’t only about storing and displaying information. It’s also about making decisions and automating repetitive work.</em></strong></blockquote><p>And these ideas will continue to appear as I move from Python toward AI and Gen AI.</p><h3>My Gen AI Journey</h3><p>So far:</p><p><strong>Day 1</strong> → Introduction to Python for Gen AI<br><strong>Day 2</strong> → Variables, Data Types, Operators, Input &amp; Output<br><strong>Day 3</strong> → Conditional Statements &amp; Loops ✅</p><p>Next:</p><p><strong>Day 4 → Functions in Python</strong></p><p>I’m documenting this journey because I want to look back later and see not just what I learned, but <strong>how my understanding evolved from Python fundamentals to building Gen AI applications.</strong></p><h4>Your Turn</h4><p>If you’re learning Python too:</p><p><strong>Which one do you find more useful — </strong><strong>for loops or </strong><strong>while loops? And why?</strong></p><p>Drop your answer in the comments. I’d love to see how others are approaching Python.</p><p>If you’re also on a <strong>Python → AI → Gen AI journey</strong>, let’s learn together! 🚀</p><h4>Tags</h4><p>Python Generative AI GenAI Artificial Intelligence PythonProgramming MachineLearning LearningInPublic 100DaysOfCode</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=07cfe1af5163" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Variables, Data Types, Operators, Input & Output]]></title>
            <link>https://sonaliballa.medium.com/python-variables-data-types-operators-input-output-1def0c2d3cb4?source=rss-33ceab3e2a99------2</link>
            <guid isPermaLink="false">https://medium.com/p/1def0c2d3cb4</guid>
            <category><![CDATA[operators]]></category>
            <category><![CDATA[input-output]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[data-types-in-python]]></category>
            <category><![CDATA[variables]]></category>
            <dc:creator><![CDATA[SONALI BALLA]]></dc:creator>
            <pubDate>Thu, 24 Sep 2026 11:52:08 GMT</pubDate>
            <atom:updated>2026-09-24T11:52:08.707Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RitiATsrBlj97OPEr9ex0Q.png" /></figure><p><em>Day 2 of my Generative AI Learning Journey</em></p><p>In my previous article, I started my <strong>Generative AI learning journey with Python</strong> and discussed why Python is important for AI, Machine Learning, and Gen AI.</p><p>Today, I’m revisiting some of the most fundamental Python concepts:</p><ul><li>Variables</li><li>Data types</li><li>Operators</li><li>Input</li><li>Output</li><li>Type conversion</li></ul><p>These concepts may look simple, but they are used constantly when building Python applications, including AI and Gen AI applications.</p><h4>1. Variables in Python</h4><p>A variable is a name used to store a value.</p><p>For example:</p><pre>name = &quot;Gen AI&quot;<br>age = 21<br>experience = 0</pre><p>Here:</p><ul><li>name stores a string</li><li>age stores an integer</li><li>experience stores an integer</li></ul><p>We can access these values using their variable names:</p><pre>print(name)<br>print(age)<br>print(experience)</pre><p>Output:</p><pre>Gen AI<br>21<br>0</pre><p>Python doesn’t require us to explicitly declare the data type of a variable.</p><p>For example:</p><pre>name = &quot;Python&quot;<br>age = 25<br>price = 99.99</pre><p>Python automatically determines the type based on the value assigned.</p><h4>2. Data Types in Python</h4><p>A data type tells us what kind of value a variable contains.</p><p>Some commonly used Python data types are:</p><p>Data TypeExampleint10float10.5str&quot;Python&quot;boolTruelist[1, 2, 3]tuple(1, 2, 3)set{1, 2, 3}dict{&quot;name&quot;: &quot;Python&quot;}NoneTypeNone</p><p>Let’s look at a few examples.</p><h4>Integer</h4><pre>age = 21</pre><h4>Float</h4><pre>price = 99.99</pre><h4>String</h4><pre>language = &quot;Python&quot;</pre><h4>Boolean</h4><pre>is_learning = True</pre><p>We can check the type using type():</p><pre>age = 21</pre><pre>print(type(age))</pre><p>Output:</p><pre>&lt;class &#39;int&#39;&gt;</pre><h4>3. Strings</h4><p>Strings are used to represent text.</p><pre>name = &quot;Generative AI&quot;</pre><p>We can perform different operations on strings.</p><pre>first_name = &quot;Gen&quot;<br>last_name = &quot;AI&quot;</pre><pre>full_name = first_name + &quot; &quot; + last_name</pre><pre>print(full_name)</pre><p>Output:</p><pre>Gen AI</pre><p>Strings are particularly important in Gen AI because much of the information we work with is text.</p><p>For example:</p><pre>prompt = &quot;Explain machine learning in simple words.&quot;</pre><p>Here, the prompt is stored as a Python string.</p><p>This is one of the simplest connections between basic Python and Gen AI.</p><h4>4. Boolean Data Type</h4><p>A Boolean has only two possible values:</p><pre>True<br>False</pre><p>For example:</p><pre>is_model_available = True<br>is_training_complete = False</pre><p>Boolean values are frequently used in conditions and program logic.</p><h4>5. Operators in Python</h4><p>Operators are symbols used to perform operations on values.</p><p>Python provides several types of operators.</p><h4>Arithmetic Operators</h4><p>These are used for mathematical calculations.</p><pre>a = 10<br>b = 3</pre><pre>print(a + b)<br>print(a - b)<br>print(a * b)<br>print(a / b)<br>print(a % b)</pre><p>Some common arithmetic operators are:</p><p>OperatorMeaning+Addition-Subtraction*Multiplication/Division%Modulus**Exponentiation//Floor division</p><h4>6. Comparison Operators</h4><p>Comparison operators compare two values.</p><pre>a = 10<br>b = 20</pre><pre>print(a == b)<br>print(a != b)<br>print(a &gt; b)<br>print(a &lt; b)</pre><p>Output:</p><pre>False<br>True<br>False<br>True</pre><p>Common comparison operators include:</p><pre>==    Equal to<br>!=    Not equal to<br>&gt;     Greater than<br>&lt;     Less than<br>&gt;=    Greater than or equal to<br>&lt;=    Less than or equal to</pre><p>These become useful when writing conditions and controlling program behavior.</p><h4>7. Logical Operators</h4><p>Logical operators are used to combine conditions.</p><p>Python provides:</p><pre>and<br>or<br>not</pre><p>Example:</p><pre>age = 22<br>has_skill = True</pre><pre>print(age &gt; 18 and has_skill)</pre><p>Output:</p><pre>True</pre><p>These operators become useful when building more complex program logic.</p><h4>8. Taking Input From the User</h4><p>Python provides the input() function to take input from the user.</p><pre>name = input(&quot;Enter your name: &quot;)</pre><pre>print(&quot;Hello&quot;, name)</pre><p>If the user enters:</p><pre>Sonali</pre><p>The output will be:</p><pre>Hello Sonali</pre><p>One important thing to remember is that input() returns a <strong>string</strong> by default.</p><p>For example:</p><pre>age = input(&quot;Enter your age: &quot;)</pre><pre>print(type(age))</pre><p>Even if the user enters:</p><pre>21</pre><p>the type will be:</p><pre>&lt;class &#39;str&#39;&gt;</pre><h4>9. Type Conversion</h4><p>Sometimes we need to convert one data type into another.</p><p>For example:</p><pre>age = input(&quot;Enter your age: &quot;)</pre><pre>age = int(age)</pre><pre>print(type(age))</pre><p>Now age becomes an integer.</p><p>Some common conversion functions are:</p><pre>int()<br>float()<br>str()<br>bool()</pre><p>Example:</p><pre>number = &quot;100&quot;</pre><pre>number = int(number)</pre><pre>print(number + 50)</pre><p>Output:</p><pre>150</pre><h4>10. Output Using print()</h4><p>The print() function is used to display information.</p><pre>name = &quot;Python&quot;</pre><pre>print(name)</pre><p>We can also print multiple values:</p><pre>language = &quot;Python&quot;<br>year = 2026</pre><pre>print(language, year)</pre><h4>11. Formatted Strings — f-Strings</h4><p>One useful feature of Python is the f-string.</p><pre>name = &quot;Python&quot;<br>version = 3.14</pre><pre>print(f&quot;I am learning {name} {version}&quot;)</pre><p>Output:</p><pre>I am learning Python 3.14</pre><p>f-strings are useful when we need to combine text and variables.</p><p>For example, when working with AI applications, we might construct dynamic prompts:</p><pre>topic = &quot;Generative AI&quot;</pre><pre>prompt = f&quot;Explain {topic} in simple terms.&quot;</pre><pre>print(prompt)</pre><p>Output:</p><pre>Explain Generative AI in simple terms.</pre><p>This is a simple example, but the same idea of dynamically creating strings can appear in larger AI applications.</p><h4>12. A Small Python Practice Program</h4><p>Let’s combine what we learned.</p><pre>name = input(&quot;Enter your name: &quot;)<br>age = int(input(&quot;Enter your age: &quot;))<br>topic = input(&quot;What are you learning? &quot;)</pre><pre>print(f&quot;\nHello {name}!&quot;)<br>print(f&quot;You are {age} years old.&quot;)<br>print(f&quot;You are currently learning {topic}.&quot;)</pre><p>This small program uses:</p><ul><li>Variables</li><li>Strings</li><li>Integers</li><li>Input</li><li>Type conversion</li><li>Output</li><li>f-strings</li></ul><h4>How These Concepts Connect to Gen AI</h4><p>At first, variables, strings, operators, and input/output may seem unrelated to Generative AI.</p><p>But they form the foundation of the applications we’ll build later.</p><p>For example, consider a simple AI application:</p><pre>user_question = input(&quot;Ask a question: &quot;)</pre><pre>prompt = f&quot;Answer this question clearly: {user_question}&quot;</pre><pre>response = model.generate(prompt)</pre><pre>print(response)</pre><p>The AI model is doing the sophisticated part, but the surrounding application still uses basic Python concepts:</p><pre>User Input<br>     ↓<br>Python Variable<br>     ↓<br>String / Prompt<br>     ↓<br>AI Model<br>     ↓<br>Response<br>     ↓<br>Python Output</pre><p>This is why I’m revisiting the fundamentals instead of skipping directly to Gen AI frameworks.</p><h3>What I Learned Today</h3><p>Today’s concepts were:</p><p>&gt; Variables<br>&gt; Python data types<br>&gt; Strings<br>&gt; Boolean values<br>&gt; Arithmetic operators<br>&gt; Comparison operators<br>&gt; Logical operators<br>&gt; Input and output<br>&gt; Type conversion<br>&gt; f-strings</p><p>The most important takeaway for me is that <strong>simple Python concepts become building blocks for much larger AI applications</strong>.</p><p>I don’t need to memorize every Python feature before moving forward. What matters is understanding the fundamentals and knowing how to apply them.</p><h4>What’s Next?</h4><p>In the next article, I’ll explore:</p><p><strong>Day 3: Conditional Statements and Loops in Python</strong></p><p>I’ll learn how Python makes decisions and repeats tasks — two fundamental concepts that are used in almost every programming application.</p><p><strong>One step at a time. One concept at a time.</strong></p><p>#Python #GenerativeAI #GenAI #ArtificialIntelligence #MachineLearning #PythonProgramming #LearningInPublic</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1def0c2d3cb4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python for Generative AI: Why I’m Starting Here]]></title>
            <link>https://sonaliballa.medium.com/python-for-generative-ai-why-im-starting-here-1909d30884aa?source=rss-33ceab3e2a99------2</link>
            <guid isPermaLink="false">https://medium.com/p/1909d30884aa</guid>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[SONALI BALLA]]></dc:creator>
            <pubDate>Wed, 23 Sep 2026 08:58:09 GMT</pubDate>
            <atom:updated>2026-09-23T08:59:09.486Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M9vweb0AuJ2Jz0uzFzGXAg.png" /></figure><p><em>Day 1 of my Generative AI Learning Journey</em></p><p>I’ve started my journey into <strong>Generative AI</strong>, and I wanted to document what I learn along the way.</p><p>Instead of only learning concepts privately, I decided to share my learning journey through a series of articles.</p><p>And where better to start than <strong>Python?</strong></p><p>Python is one of the most widely used programming languages in Artificial Intelligence, Machine Learning, Data Science, and Generative AI.</p><p>Although I have already learned the basics of Python, I’m revisiting and organizing the concepts while documenting them because I want to build a stronger foundation for the Gen AI concepts that come later.</p><p><strong>What is Python?</strong></p><p>Python is a high-level, general-purpose programming language known for its:</p><ul><li>Simple and readable syntax</li><li>Large ecosystem of libraries</li><li>Beginner-friendly learning curve</li><li>Support for multiple programming paradigms</li><li>Strong use in AI, ML, Data Science, automation, and web development</li></ul><p>A simple Python program looks like this:</p><pre>print(&quot;Hello, Generative AI!&quot;)</pre><p>Python code is relatively easy to read, which makes it useful for beginners as well as experienced developers.</p><h4>Why is Python Important for Generative AI?</h4><p>Generative AI involves technologies such as:</p><ul><li>Large Language Models (LLMs)</li><li>Natural Language Processing (NLP)</li><li>Deep Learning</li><li>Transformers</li><li>Retrieval-Augmented Generation (RAG)</li><li>AI Agents</li><li>Embeddings</li><li>Vector Databases</li><li>Model APIs</li></ul><p>Python has a huge ecosystem around these technologies.</p><p>For example, while learning Gen AI, I will come across libraries and frameworks such as:</p><pre>NumPy<br>Pandas<br>PyTorch<br>TensorFlow<br>Transformers<br>LangChain<br>LlamaIndex</pre><p>Python allows us to work with these tools and build applications around AI models.</p><h4>Python’s Role in the Gen AI Journey</h4><p>I’m thinking about Python as the <strong>foundation</strong> of my Gen AI journey.</p><p>A simplified path looks something like this:</p><pre>Python<br>   ↓<br>NumPy &amp; Pandas<br>   ↓<br>Machine Learning<br>   ↓<br>Deep Learning<br>   ↓<br>NLP<br>   ↓<br>Transformers<br>   ↓<br>Large Language Models<br>   ↓<br>Generative AI<br>   ↓<br>RAG &amp; AI Agents<br>   ↓<br>Gen AI Projects</pre><p>This doesn’t mean that every Gen AI developer needs to master every topic before building anything.</p><p>However, having a good Python foundation makes it much easier to understand and work with the tools used in AI development.</p><h4>What Python Concepts Do I Need for Gen AI?</h4><p>I don’t need to learn every advanced Python feature before starting Gen AI.</p><p>For my journey, I’m focusing on the concepts that will actually help me later.</p><h4>Core Python</h4><ul><li>Variables</li><li>Data types</li><li>Operators</li><li>Conditional statements</li><li>Loops</li><li>Functions</li><li>Lists</li><li>Tuples</li><li>Sets</li><li>Dictionaries</li><li>List/dictionary comprehensions</li></ul><h4>Important Python Concepts</h4><ul><li>File handling</li><li>Exception handling</li><li>Object-Oriented Programming</li><li>Modules</li><li>Packages</li><li>Virtual environments</li><li>Working with APIs</li></ul><h4>Python Libraries</h4><p>After the fundamentals, I’ll move toward libraries commonly used in data and AI workflows:</p><ul><li>NumPy</li><li>Pandas</li><li>Matplotlib</li><li>Scikit-learn</li><li>PyTorch</li></ul><p>Later, I’ll explore libraries and frameworks specifically related to Gen AI.</p><h4>A Small Python Example</h4><p>Let’s look at a simple example.</p><pre>name = &quot;Gen AI&quot;</pre><pre>topics = [&quot;Python&quot;, &quot;Machine Learning&quot;, &quot;Deep Learning&quot;]</pre><pre>print(&quot;I&#39;m learning&quot;, name)<br>print(&quot;My topics:&quot;, topics)</pre><p>Output:</p><pre>I&#39;m learning Gen AI<br>My topics: [&#39;Python&#39;, &#39;Machine Learning&#39;, &#39;Deep Learning&#39;]</pre><p>This example is very simple, but it already uses some fundamental Python concepts:</p><ul><li>Variables</li><li>Strings</li><li>Lists</li><li>print()</li><li>Function calls</li></ul><p>These basic concepts become building blocks for more complex programs.</p><h4>Python and AI: A Simple Example</h4><p>Suppose I want to interact with an AI model through an API.</p><p>The actual application can involve concepts such as:</p><pre>prompt = &quot;Explain Generative AI in simple words&quot;</pre><pre>response = model.generate(prompt)</pre><pre>print(response)</pre><p>The actual API and model code can be much more complex, but the surrounding application is still built using programming concepts such as:</p><ul><li>Variables</li><li>Functions</li><li>Strings</li><li>Objects</li><li>Error handling</li><li>Modules</li><li>APIs</li></ul><p>That’s why I’m starting by strengthening my Python foundation.</p><h4>What I Want to Learn From This Python Phase</h4><p>Since I’ve already studied Python, my goal isn’t simply to memorize syntax again.</p><p>Instead, I want to:</p><ol><li>Revise the fundamentals</li><li>Understand concepts more deeply</li><li>Practice writing clean Python code</li><li>Connect Python concepts to AI/ML</li><li>Build small projects</li><li>Become comfortable working with AI libraries and APIs</li></ol><p>Most importantly, I want to understand <strong>why</strong> I’m learning something, not just <strong>how</strong> to write it.</p><h4>What I Learned Today</h4><p>Today’s main takeaway is that <strong>Python isn’t the destination of my Gen AI journey — it’s one of the foundations.</strong></p><p>I already know many of these Python concepts, but revisiting them with an AI-focused perspective helps me understand where they fit into the bigger picture.</p><p>My goal isn’t to learn everything at once.</p><p>It’s to build step by step.</p><p><strong>Python → ML → Deep Learning → NLP → Transformers → LLMs → Generative AI → Projects</strong></p><p>And this is just <strong>Day 1.</strong></p><h4>What’s Next?</h4><p>In the next article, I’ll cover:</p><p><strong>Day 2: Python Variables, Data Types, Operators, Input &amp; Output</strong></p><p>I’ll continue documenting what I learn, the concepts I revise, and how they connect to my goal of becoming a <strong>Generative AI Engineer</strong>.</p><p>If you’re also learning Python, AI, or Generative AI, feel free to follow along.</p><p>Let’s learn and build together.</p><h4>Tags</h4><p>Python Generative AI Artificial Intelligence Machine Learning GenAI</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1909d30884aa" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>