Python: 05 🐍 Python Iterables: Diving Deeper 🚀 We'll work on different complex types (range, list etc.) and strings iteration. We've already known the for loops, now let's dive into deeper and know what is range function returns. 🔍 We will use a built in 'type' function to get the type of an object. 🛠️ For example: type(5) .. it will return <class 'int'>; that means number 5 is an integer value 🔢 type(range(5)) .. it will return <class 'range'>; that means we get the value from a range function that means its an object of type range! 🧊 Primitive vs. Complex Types 💡 In python we have primitive types like numbers, strings, Booleans. We also have so many complex types, 'range' is one of those complex types. So interesting concept of range is, it is iterable which means we can iterate over it or use it in a for loop. That is why we can write code like this: for x in range(3): Here x can hold number in the range in each iteration. 🔄 Result: 1 2 3 Strings are also iterable! 🧵 For example: for x in "python": print(x) It will return: ✨ p ✨ y ✨ t ✨ h ✨ o ✨ n Which means x will hold one character from the string in each iteration. 🔡 List Iteration 📋: for x in [1, 2, 3, 4,..,n]: print(x) It will return: 1 2 3 4 ... ... ... nth X will hold one object from the list in each iteration. 🎯 #PythonProgramming #PythonDeveloper #Coding #python #iterator #DataScience #pythondeveloper #programmer
Python Iterables: Range, Lists, and Strings
More Relevant Posts
-
Python functions with fixed signatures break the moment you need to forward arguments across abstraction boundaries. *args and **kwargs solve that — and this python tutorial goes well past the syntax. — How CPython actually handles variadic calls at the C level (PyTupleObject, PyDictObject, and why there's a real allocation cost) — Why a defaulted parameter before *args is effectively unreachable via positional calling — and the idiomatic fix — The difference between *args isolating the mapping vs sharing mutable values inside it — ParamSpec (PEP 612) for preserving decorator signatures through the type system — TypedDict + Unpack (PEP 692, Python 3.12) for per-key precision on **kwargs — inspect.Parameter.kind for reading variadic signatures at runtime — the foundation of FastAPI and pytest's dispatch logic — Lambda variadic syntax, functools.wraps, kwargs.setdefault patterns, and common SyntaxErrors caught at parse time Includes interactive quizzes, spot-the-bug challenges, a design decision review, and a 15-question final exam with a downloadable certificate of completion. Full guide: https://lnkd.in/gHkdvCn5 #Python #PythonProgramming #SoftwareDevelopment
To view or add a comment, sign in
-
Build a RAG pipeline from scratch in Python without LangChain Learn to build a RAG pipeline in Python from scratch using ChromaDB and OpenAI embeddings — no LangChain required. Read the full post 👇 https://lnkd.in/gBHKATvy #GenerativeAI #AI #WebDevelopment #PHP #Python #Developer #LLM
To view or add a comment, sign in
-
Build a RAG pipeline from scratch in Python without LangChain Learn to build a RAG pipeline in Python from scratch — chunk documents, embed with OpenAI, store in ChromaDB, and query with Claude. Read the full post 👇 https://lnkd.in/gBHKATvy #GenerativeAI #AI #WebDevelopment #PHP #Python #Developer #LLM
To view or add a comment, sign in
-
F-strings in Python — Not Just Cleaner. Fundamentally Better. Python has had three ways to format strings over its history. If you’ve only learned the language recently, you might not have encountered the older two — but you will, because they still appear in legacy codebases, documentation, and tutorials written before Python 3.6. The first was % formatting, borrowed from C: name = "Andres" print("Hello, %s. You have %d messages." % (name, 5)) It works. But the syntax is cryptic, the order of arguments is error-prone, and it becomes harder to read as soon as you add more than one variable. The second was .format(), introduced in Python 3.0: print("Hello, {}. You have {} messages.".format(name, 5)) An improvement — more explicit, more flexible. But the variables and the placeholders are still separated. To understand what goes where, your eyes have to travel back and forth across the line. Then Python 3.6 introduced f-strings: print(f"Hello, {name}. You have {5} messages.") The variable lives inside the string, exactly where it appears in the output. No positional arguments. No external references. The code reads the way the sentence reads. Beyond readability, f-strings also evaluate expressions directly inline — which means you can do this: hours = 7.5 print(f"Weekly total: {hours * 5} hours") No intermediate variable needed. And in terms of performance, f-strings are consistently faster than .format() because they are parsed closer to compile-time rather than evaluated fully at runtime. Knowing all three methods matters. Understanding why f-strings became the standard tells you something about how Python evolves — always toward clarity. #Python #PythonMOOC2026 #BackendDevelopment #SoftwareEngineering #LearningInPublic #UniversityOfHelsinki
To view or add a comment, sign in
-
-
Python may get async yield from. Nice syntax. Potentially ugly consequences. At first glance, it feels like a natural extension of yield from for async generators. It is convenient. It is visually consistent. And yes, sometimes it would make code cleaner. But async generators are already one of those Python features that look simpler than they really are. Go a bit deeper, and you run into things like explicit closing, cleanup that does not happen when you expect, wrong assumptions about generator behavior, dependence on an event loop just to finish safely, and bugs that appear the moment multiple tasks touch the same flow. That is the real discussion. Not whether async yield from looks elegant. But whether it makes a sharp edge even sharper. This is one of the things I find most interesting in Python: a feature can look like syntax sugar on the surface, while quietly expanding the state model underneath. And in production systems, that difference matters. Complexity in Python rarely arrives as one dramatic failure. It shows up as a chain of locally reasonable decisions that slowly become hard to reason about as a whole. That is why async-heavy systems need more than code that “works”. They need clear lifecycle rules, ownership boundaries, and predictable behavior under failure. Curious where others land on this: Would async yield from make async Python better, or just easier to misuse?
To view or add a comment, sign in
-
🚀 Python GIL vs No-GIL: Real FastAPI Benchmarks (Python 3.13) Python is going through one of its biggest shifts in decades — the Global Interpreter Lock (GIL) is now optional in Python 3.13. But the real question is: 👉 Does removing the GIL actually improve real-world performance? A recent benchmark using FastAPI gives some interesting insights 👇 💡 Key Takeaways: 🔹 True parallelism is finally possible With the GIL removed, Python threads can run across multiple CPU cores — something that wasn’t possible before. 🔹 Massive gains for CPU-bound workloads In multi-threaded scenarios, performance can scale significantly (even 3–4x in some cases) when tasks are parallelizable. 🔹 FastAPI doesn’t magically get faster FastAPI is primarily async-based (single-threaded concurrency), so it doesn’t automatically benefit from no-GIL unless you switch to thread-based execution. 🔹 Trade-offs are real Single-thread performance can drop due to added locking overhead Many libraries (NumPy, Pandas, etc.) aren’t fully ready yet Thread-safety becomes your responsibility 🔹 Still experimental Free-threaded Python in 3.13 is not production-ready yet — but it’s a huge step forward. 🔥 What this means for developers: If you’re building CPU-heavy APIs, no-GIL could be a game changer If you rely heavily on async + I/O, impact will be limited The ecosystem still needs time to adapt 👉 Curious to hear your thoughts: Would you adopt no-GIL Python today, or wait for ecosystem stability? #Python #FastAPI #BackendDevelopment #Concurrency #Performance #SoftwareEngineering
To view or add a comment, sign in
-
-
yield is one of those Python keywords that looks simple until someone asks you to explain it. Most developers can tell you a function with yield in it produces values and works in for loops. Fewer can explain why that same function doesn't actually run when you call it. Turns out, that's the whole point. Generators (functions with yield) are functions that pause mid-execution and resume exactly where they left off: local variables, loop counters, everything intact. In my Python Context Managers series, I'm covering generators as a dedicated article because they are not a standalone concept. They are the engine behind @contextmanager, a cleaner way to build context managers in Python. You can't fully understand one without understanding the other. This article is a deep dive into generator functions: https://lnkd.in/dSNegaWK A function that remembers where it left off changes everything. #Python #SoftwareEngineering #Backend #Programming #WebDevelopment #BuildBreakLearn
To view or add a comment, sign in
-
FastAPI + No-GIL Python might be one of the most important backend shifts this year Most of the conversation in AI has been about models getting faster. But something equally important is happening at the runtime level. With FastAPI 0.136.0, support for Python’s free-threaded (No-GIL) builds is now becoming practical to experiment with. I wanted to understand what this actually means in a real API scenario. So I ran a simple benchmark: - Python 3.12 (with GIL) - Python 3.13 free-threaded build (No-GIL) Same FastAPI app Same endpoints No code changes For CPU-bound workloads, I saw up to ~8x improvement. This isn’t surprising when you think about it. For years, the Global Interpreter Lock has limited Python’s ability to fully use multiple cores in a single process. Threads never really meant parallel execution for CPU-heavy tasks. Most of us worked around it using multiprocessing, task queues, or by adding more infrastructure. No-GIL changes that model. Now threads can actually run in parallel across cores, which means CPU-heavy APIs can scale more naturally without increasing system complexity. Where this becomes especially relevant: - ML inference APIs - Data processing pipelines - Feature engineering workloads - Real-time analytics backends That said, there are some important caveats: - Python 3.13’s free-threaded mode is still experimental - Not all libraries are thread-safe yet - The ecosystem will take time to stabilize So this is not a “move everything to No-GIL today” moment. But it is a strong signal of where Python is heading. For a long time, the trade-off was clear: Python was easy to use, but not ideal for CPU-bound parallelism. That trade-off may not hold for much longer. Curious to hear how others are thinking about this. Are you planning to experiment with No-GIL Python, or waiting for the ecosystem to mature?
To view or add a comment, sign in
-
-
Day 27 Python Full Stack Development Journey Today’s focus was on understanding Polymorphism in Python and its key concepts. 🔹 Introduction to Polymorphism Polymorphism means “many forms”. In Python, it allows the same function, method, or operator to behave differently depending on the object or data type. Example: Python print(len("Hello")) # String length print(len([1,2,3])) # List length 🔹 Important Terminologies in Polymorphism Method Overriding Same method name in parent and child class, but different implementation. Duck Typing Python doesn’t check object type, it checks behavior. (“If it looks like a duck and acts like a duck, it is a duck.”) Dynamic Typing Variable type is decided at runtime, not fixed. 🔹 Operator Overloading Operator overloading allows operators to have different meanings for different objects. Example: Python print(5 + 3) # Addition print("Hello " + "World") # String concatenation We can also overload operators in user-defined classes. 🔹 Magic Methods (Dunder Methods) Magic methods are special methods in Python that start and end with double underscores (__). They are used to define behavior for operators and built-in functions. 👉 Common Magic Methods: __init__ → Constructor __str__ → String representation __add__ → Addition operator __len__ → Length __repr__ → Official representation 👉 Example: Python class Demo: def __init__(self, x): self.x = x def __str__(self): return f"Value is {self.x}" obj = Demo(10) print(obj) Thanks for our CEO G.R NARENDRA REDDY sir and Global Quest Technologies
To view or add a comment, sign in
-
-
print() and input() in Python — Two Functions. The Entire Conversation. Before loops, before functions, before data structures — any interactive program needs to solve two basic problems: how to send information to the user, and how to receive information from them. In Python, that’s where print() and input() come in. They’re the first two built-in functions the Helsinki MOOC introduces, and the reason is straightforward: without them, your program runs silently and alone. Nothing goes out, nothing comes in. print() handles output. It takes whatever you pass it and displays it in the terminal. That can be a string, a number, a variable, or a combination of all three: print("Current temperature:", temperature, "°C") Simple. But the moment you add it to your code, your program starts communicating. input() handles the other direction. It pauses the program, displays a message to the user, and waits. Whatever the user types is returned as a string that your program can then work with: city = input("Enter your city: ") One detail worth noting early: input() always returns a string, regardless of what the user types. If you ask for a number and plan to do arithmetic with it, you need to convert it explicitly. That’s not a flaw — it’s Python being precise about types, which is a habit worth developing from the start. Together, these two functions establish a pattern that scales across the entire language: programs receive data, process it, and return a result. print() and input() are just that pattern in its most direct form. Everything more complex is built on top of this. #Python #PythonMOOC2026 #BackendDevelopment #SoftwareEngineering #LearningInPublic #UniversityOfHelsinki
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