🚀 Day 33 of My Python Full-Stack Journey 🐍 Today I learned about the Scope of Variables in Python. Variable scope determines where a variable can be accessed within a program. Understanding scope helps in writing cleaner, more organized, and error-free code. 🔹 Types of Variable Scope in Python: • Local Scope – Variables defined inside a function and accessible only within that function. • Global Scope – Variables defined outside functions and accessible throughout the program. • Enclosing Scope – Variables in the outer function that can be accessed by nested functions. • Built-in Scope – Predefined names in Python that are always available (like print(), len(), etc.). 🔹 What I practiced today: • Creating and using local and global variables • Understanding how variables behave inside functions • Learning the LEGB rule (Local, Enclosing, Global, Built-in) • Writing programs to see how scope affects variable access Learning variable scope helps avoid conflicts between variables and improves code readability. Step by step, I’m building a stronger foundation in Python programming. 💻✨ #Python #PythonLearning #FullStackJourney #CodingJourney #LearnPython #DeveloperJourney #100DaysOfCode
Python Variable Scope Explained: Local, Global, Enclosing, Built-in
More Relevant Posts
-
🚀 Python Series – Day 2: Installing Python & Writing Your First Program Yesterday, we understood What is Python & Why it is powerful. Today, let’s take the first real step— installing Python and writing your first program 💻 🔧 Step 1: Install Python 1. Go to the official website: https://www.python.org 2. Download the latest version 3. While installing, IMPORTANT: ✔️ Check “Add Python to PATH” ▶️ Step 2: Verify Installation Open Command Prompt / Terminal and type: python --version 🧠 Step 3: Your First Python Program print("Hello, World!") 💡 What does this mean? print() → Used to display output "Hello, World!"→ Text (string) 🎯 Why is this important? This is your first step into coding. Every expert once started with this simple line. 🔥 Pro Tip: Try this: print("I am learning Python 🚀") ❓ Question for you: Have you written your first Python program yet? 👉 Comment YES / NO— I’d love to know! 📌 Tomorrow: Variables & Data Types (Most Important Topic!) #Python #DataScience #Coding #Programming #LearnPython #Beginners #Tech #MustaqeemSiddiqui
To view or add a comment, sign in
-
-
🚀 **Day 7 of Learning Python** Today I learned about **Functions** in Python — a major step toward writing cleaner and reusable code! 🔧 A function is a block of code that performs a specific task and can be reused whenever needed. Instead of repeating code, we can simply call a function. 👉 **Basic syntax:** `def function_name(parameters):` `# code block` 💡 **Example:** ``` def myfunction(name): return f"Hello, {name}!" print(myfunction("Prathap")) ``` ✨ **What I learned:** ✅ Functions help organize code better ✅ They improve readability ✅ They save time by avoiding repetition ✅ You can pass data using parameters and get results using return values 🔥 It feels great to move from just writing code to structuring it properly! 📌 **Key takeaway:** Good programmers don’t just write code — they write reusable code. #Python #LearningJourney #30DaysOfCode #Functions #Coding #Programming #DeveloperJourney
To view or add a comment, sign in
-
Day 1/30 Why Python code looks so simple (especially to beginners) I wrote a few lines of Python today, and my first reaction was: “Why does this look… too easy?” Coming from C++, I’m used to writing things like: int x = 10; But in Python, it’s just: x = 10 No type. No semicolon. No extra syntax. At first, it feels great. Less to write, less to think about. But then I realized: Python isn’t removing complexity. It’s just hiding it. The language handles a lot behind the scenes, so you can focus on logic instead of types or memory. That’s probably why beginners find it easier to start with. But coming from C++, it feels different. I’m used to having more control. Python feels more like trusting the system to do the right thing. Still getting used to it, but I can already see why people move faster with it. Let’s see how this plays out over the next few days. #Python #cpp#LearningInPublic #30DaysOfCode
To view or add a comment, sign in
-
-
Day 46 : Python Conditional Statements – If/Else Today I understood the conditional statements used in Python. Hands-on : - Today I learned about conditional statements in Python, which are used to control the flow of a program based on conditions. - I started with the basic syntax of the if statement, understanding how Python evaluates conditions and executes code blocks. -I then explored the if/else statement, which allows execution of alternate code when a condition is false. - Moving forward, I practiced if/elif/else statements to handle multiple conditions efficiently. - I also learned how to write if/else in a single line (ternary operator), which makes simple conditions more concise. - Finally, I explored nested if/else statements, where one condition is placed inside another to handle more complex logic. Result : - Successfully understood how to implement conditional logic in Python using different forms of if/else statements. Key Takeaways : - If statement executes code only when a condition is true. - If/Else provides an alternative execution path. - If/Elif/Else helps handle multiple conditions efficiently. - One-line if/else (ternary) makes code concise for simple conditions. - Nested conditions allow handling complex decision-making scenarios. #Python #Programming #DataAnalytics #LearningJourney #ConditionalStatements #CodingBasics #DataScience #BeginnerPython #AnalyticsSkills
To view or add a comment, sign in
-
-
🚀 Day 12 of Python Coding Challenge 📌 Problem: Count Total Number of Characters in a File Understanding file handling is a fundamental skill in Python. Today’s task is to count the total number of characters in a given file. 💡 Approach: Open the file in read mode Read the file content Use len() to count characters 🧠 Python Code: def count_characters(file_path): try: with open(file_path, 'r') as file: content = file.read() return len(content) except FileNotFoundError: return "File not found." # Example usage file_path = "sample.txt" result = count_characters(file_path) print("Total characters in file:", result) ✅ Sample Output: Total characters in file: 12 🔍 Key Learnings: File handling using open() Using with statement for safe file operations Applying len() on strings 📢 Pro Tip: If you want to exclude spaces or newline characters, you can filter them before counting! 🔥 Keep Learning, Keep Growing! Follow along for more daily Python problems. #Python #CodingChallenge #Day12 #LearningJourney #30DaysOfCode
To view or add a comment, sign in
-
🐢 Normal for-loop vs 🐇 List Comprehension in Python Python lets you write code that’s both readable and efficient. This simple example shows how a normal for-loop and a list comprehension can achieve the same result — creating a list of squares — but in very different styles. 💡 Why it matters: List comprehensions make your code shorter, cleaner, and easier to read Great for data processing, problem-solving, and real-world projects Python isn’t just about writing code — it’s about thinking in elegant solutions! #Python #CodingTips #ListComprehension #Programming #DataAnalysis #ProblemSolving #LearningByDoing #100DaysOfCode
To view or add a comment, sign in
-
-
📚 Day 29/130 — Python Syntax Basics Today in my Python Programming Series, let’s understand the foundation of writing Python code 👇 🔹 What is Python Syntax? Python syntax is the set of rules that defines how Python code is written and understood by the computer. 🔹 Simple Understanding: 👉 Syntax = Grammar of programming language 🔹 Key Rules in Python: • No need for semicolons (;) ❌ • Indentation is important (spaces matter!) 📏 • Easy-to-read structure 👀 • Code is written line by line 🔹 Example: print("Hello World") 👉 This is your first Python program 🎉 🔹 Why Syntax is Important? • Helps write correct code ✔️ • Avoids errors ⚠️ • Improves readability 👓 🔹 Key Idea: 👉 Clean and correct syntax = better and error-free code 📊 See the diagram below for better understanding. 📌 Tomorrow’s Topic: 👉 Python Variables #Python #Programming #Coding #TechLearning #LearningInPublic #Students #Developer #100DaysOfCode
To view or add a comment, sign in
-
-
Python type annotations let you attach type information directly to variables, function parameters, and return values. They do not change how Python runs your code at runtime—but they transform what your editor and your teammates can understand about it before a single line executes. https://lnkd.in/g4JXgCgi #python
To view or add a comment, sign in
-
Day 2 of my Python & DSA learning journey 🚀 Today I learned the difference between print() and return in Python. ❓ What is the difference between print() and return? Both are used to work with values in Python, but they behave differently. 📌 print() • It displays the output on the screen • It does not send the value back to the function caller 📌 return • It sends the value back to the place where the function was called • It allows the value to be used later in the program 💻 Example in Python def add(a, b): return a + b result = add(5, 3) print(result) Here the function uses return to send the result back, and print() is used to display it. Output: 8 Understanding the difference between print() and return is very important when writing functions in Python. 🔥 Question for developers: When do you prefer using return instead of print() inside a function? #Python #DSA #Coding #Programming #LearningInPublic #100DaysOfCode
To view or add a comment, sign in
-
🚀 Ever wondered how to efficiently use loops in Python? Let's dive in and unravel the power of Python loops! 🐍 Python loops are used to iterate over sequences like lists, tuples, and dictionaries, executing the same block of code repeatedly. This simplifies tasks like calculations, data processing, and repetitive actions in your programs. Developers benefit greatly from mastering loops as they streamline code, improve efficiency, and help automate repetitive tasks. By understanding how loops work, developers can write cleaner code, reduce errors, and enhance their problem-solving skills. Plus, loops are fundamental in programming and are widely used in various applications. Step by Step Breakdown: 1. Initialize a list of items. 2. Use a "for" loop to iterate over each item. 3. Perform an action on each item within the loop. 💡 Pro Tip: Remember to choose the appropriate loop (for or while) based on the specific task and data structure you are working with for optimal performance and readability. ⚠️ Common Mistake Alert: Forgetting to update the loop control variable correctly can lead to infinite loops, causing your program to hang or crash. 🤔 What's your favorite application of loops in Python? Share with us in the comments below! 🌐 View my full portfolio and more dev resources at tharindunipun.lk #PythonLoops #CodeEfficiency #Programming101 #DeveloperTips #AutomationInCoding #LearnToCode #PythonProgramming #TechSkills #ProblemSolving #CodeMastery
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development