Python
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax and Data Types
-
Section 3: Collections
-
39: Set Operations: Union, Intersection, Difference
-
Section 4: Control Flow
-
Section 5: Functions
-
Section 6: Turtle Graphics and Early Practice Projects
-
Section 7: Working with Files and I/O
-
Section 8: Regular Expressions
-
Section 9: Object-Oriented Python
-
Section 10: Error Handling
-
Section 11: Modules and Packages
-
Section 12: Iterators, Generators, and Functional Tools
-
Section 13: Decorators and Metaprogramming
-
Section 14: Concurrency and Parallelism
-
Section 15: Working with Dates, Times, and Numbers
-
Section 16: Standard Library Deep Dive I: Data Structures
-
Section 17: Standard Library Deep Dive II: System and Introspection
-
Section 18: Standard Library Deep Dive III: Security and Encoding
-
Section 19: Standard Library Deep Dive IV: Text and Data Utilities
-
Section 20: Networking and Web Basics
-
Section 21: Working with Databases
-
Section 22: Testing and Quality
-
Section 23: Advanced Typing
-
Section 24: Context Managers and Resource Handling
-
Section 25: Text, Unicode, and Binary Data
-
Section 26: More Functional and Iteration Tools
-
Section 27: Data Validation and Configuration
-
Section 28: Working with Images and Media
-
Section 29: Property-Based and Documentation Testing
-
Section 30: Packaging and Deployment
-
Section 31: Performance and Internals
-
Section 32: Design Patterns in Python
-
Section 33: GUI Programming
-
Section 34: Security Basics
-
Section 35: Data Structures and Algorithms
-
Section 36: Practical Projects
-
Section 37: Capstone Projects
-
Section 38: Interview and Algorithm Practice
-
Section 39: Writing Idiomatic Python
3: Using the Interactive Interpreter (REPL)
I've found that whenever I'm stuck on a logic problem or I can't remember exactly how a specific Python method behaves, the last thing I want to do is create a new file, save it, and run it through the terminal. It's too much friction. Instead, I just jump into the interactive interpreter—the REPL.
Just wanting a quick answer
Let's say I'm working on a project and I need to know what happens if I try to multiply a string by a number. I don't need a whole program for this. I'll just type python3 (or python depending on your setup) into my terminal. I see those three arrows—>>>—and I know Python is officially listening.
>>> "Python" * 3
'PythonPythonPython'
Notice how I didn't have to wrap that in a print() function? In a standard script, that line would do absolutely nothing visible. But here, the interpreter "evaluates" the expression and immediately "prints" the result. This is the core of the Read-Eval-Print Loop. It's a conversation.
Keeping a bit of state
Now, let's say I'm trying to figure out a pricing formula. I can treat the REPL like a scratchpad, defining variables on the fly to see how they interact. I'll set a base price and a tax rate, then try to combine them.
>>> price = 19.99
>>> tax = 0.07
>>> price * tax
1.3993
That's not quite a clean currency format. I can refine my approach immediately without restarting. I'll try the round() function right here to see if it gives me what I want.
>>> round(price * tax, 2)
1.4
Wait, 1.4? I was expecting 1.40. This is where the REPL shines. I've just discovered that Python's round() doesn't force trailing zeros for floats. Now I know that if I want "1.40" in my actual app, I'll need to use string formatting instead of round(). I saved myself ten minutes of writing a script only to be confused by the output.
The "Wait, why didn't that run?" moment
Here is where people usually get tripped up. I want to test a quick loop to see if I can filter a list. I'll type this in:
>>> numbers = [1, 2, 3, 4, 5]
>>> for n in numbers:
... if n > 2:
... print(n)
...
I hit Enter after the print(n) line and... nothing happened. I'm staring at the ... prompt. I might think the computer froze, but it hasn't. Python is just telling me, "You started a block (the loop and the if-statement), and I'm waiting for you to finish it."
Because the REPL relies on indentation to know when a block ends, I have to hit Enter one more time on a completely blank line to tell Python I'm done with the loop. Once I do that, the results pop out immediately.
3
4
5
>>>
Getting out of here
Once I've got my answer or my logic is verified, I need to get back to my actual code. You can use exit() or quit(), but I've always preferred the keyboard shortcut Ctrl+D (on macOS/Linux) or Ctrl+Z followed by Enter (on Windows). It's faster and feels more like a "hard stop" to the session.
📋 Practical Task
Testing the Case-Insensitive User Handle
Imagine you are building a system where usernames should be treated as case-insensitive (so "DevUser123" is the same as "devuser123"). Before you write the actual registration logic in your script, use your interactive interpreter (REPL) to experiment and find the best way to handle this.
Your goal: Open your REPL and perform the following exploration:
- Create a variable called
stored_userand assign it the value"Admin_Python". - Create a second variable called
input_userand assign it the value"admin_PYTHON". - Try comparing them directly using
==and observe the result. - Experiment with the
.lower()or.casefold()string methods on both variables within a comparison to see if you can make the resultTrue. - Once you've successfully made the comparison return
True, exit the REPL.
There are no comments for now.