This is a small documentation
Variables can only contain letters, numbers and underscores.
For Variables, use underscores to separate words.
Avoid using keywords / reserved words / function names for your Variables.
Short variable names, but descriptive of what you're trying to do.
Take care using lowercase l(L) and 0(O). They look like one and zero.
This editor is called ZED.
Don't try to be a master at creating variable names, it comes with experience.
Avoid using uppercase letters for variables unless you are a pro.
Variable errors when you're typing fast. print(mesage) instead of print(message)
In short, create variable names that are easy to spell.
Else, you will spend hours searching for something you don't know how to spell.
The best way to learn programming is by doing.
You do questions. So, in our practice sessions here, we are going to be doing.
I will start by doing questions immediately for these first two chapters.
Let me start up vscode. I use Zed for writing stuff, coz the font is really cool.
VSCode for running the code. IDLE for testing out some things.
✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅
I WISH GOOGLE SITES HAD FIND AND REPLACE 🤔
AND I COULD EMBED CODE FROM ANY LANGUAGE...
✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅
F-STRINGS VS FORMAT - Covered later in string formatting
F-strings use the variable inside the curly brackets.
For the other type of string formatting, (.format), use empty brackets
.format is difficult to track variables.
f-strings give you an easier coding experience, since its self-documenting.
For those who don't know am not a beginner at all, am just reminding myself how things go over here.
Neither am I a pro developer, am somewhere in the universe of coding.
Just there....
I have done some django projects and some other languages, but python, I completely forgot everything.
Here's my portfolio, you'll find cool stuff.
I personally hate coding, been reading code all my life.
The thing is, to progress in some areas of tech, you need to know how to write code.
I am doing this in public so that I atleast have someone keep me accountable and see my progress.
Am ready to learn with you, so am technically a beginner-mediate... beginner-intermediate, I dont know?🤣
CASES IN PYTHON - LOWER, UPPER, TITLE and A FEW MORE...
Title case - Hello World
When people are registering on your website, you'd want to format all the names for uniformity in the database.
Title case does that properly.
We can also use it for GUI programming where you format the title of your application or any other data you'd want displayed properly.
Eg linux programming app to Linux Programming App
In PyQT: label.setText(os_name.title()) does that linux thing to Linux, which looks better.
Use .upper() to automatically capitalize a license key or a department code as the user types, providing immediate visual feedback that they are entering the data correctly.
Used purely for human-readable display in interfaces.
Welcome Messages: Displaying Welcome, Nick Name on a dashboard.
Nav-Bar Links: Turning a database category latest_news into Latest News.
PDF Generation: Auto-formatting a report title for a client.
E-commerce: Showing product names like Midnight Blue Keyboard.
Contact Lists: Cleaning up a list of names for a PyQt address book.
Lowercase - hello world (the standardizer)
Used when you need to compare two things without worrying about how the user typed them.
Email Login: Ensuring User@Email.com matches user@email.com in the database.
Search Filtering: Making a "Search" bar find "Python" even if the user types "python".
URL Slugs: Converting a blog title into a lowercase URL link. Django urls and database records need to be in small letters so that things don't error out.
Command Line Tools: Letting a user type QUIT, Quit, or quit to exit a program.
Extension Checking: Verifying if a file ends in .jpg regardless of if it's .JPG.
The result?
Uppercase - HELLO WORLD
Used for things that need to stand out or follow strict naming conventions.
Error Codes: Displaying a critical system failure like CRITICAL_OVERHEAT.
Legal Disclaimers: Making "Terms and Conditions" headers pop in a GUI.
Environment Variables: Formatting keys in a .env file for a Django backend.
State Abbreviations: Converting user input ny to NY for shipping forms.
Regex Anchors: Creating loud "Flags" in a text-parsing script for reverse engineering.
Result? We did the UPPERCASING and then we printed 3 exclamations after the status.
We could also have matched it as:
print(status.upper() + "!" *3
So, we'd get:
SYSTEM_ERROR!!!
...from the final line of code.
.capitalize() — The Sentence Architect
Used for long-form text where only the start of the thought should be uppercase.
It only capitalizes the very first letter of the entire string. Everything else is forced to lowercase.
Chatbot Responses: Ensuring a bot starts its sentence with a capital letter.
Blog Snippets: Formatting the "First line" of a post preview.
Instruction Labels: Making a PyQt hint say Enter your password here.
Log Entries: Starting a timestamped log with a proper sentence case.
Dynamic Captions: Auto-generating a caption for a photo in a web app.
In our result here, N as the first letter in the first word of our sentence, is capitalized, the rest of the words have small letters.
.swapcase() — The Visual Scrambler
Used for specific UI toggles or quick text corrections.
Fix Caps Lock Feature: A button in a text editor to fix accidental typing.
Security Obfuscation: Making a string harder to read for basic eye-balling in a binary.
Artistic UI Effects: Creating a glitch text effect in a game.
Developer Debugging: Quickly seeing which parts of a string were originally lower vs upper.
Input Toggling: A shortcut to invert a highlighted selection in a GUI.
The Flip mode. Capitals become lowercase; lowercase become capitals.
⚙️ How .swapcase() Actually Works
Python doesn't look at words; it looks at Individual Characters and their Unicode values.
Think of it as a simple If/Else switch inside the Python source code:
IF the character is Uppercase (A-Z) → THEN make it Lowercase (a-z).
ELSE IF the character is Lowercase (a-z) → THEN make it Uppercase (A-Z).
ELSE (like a space, number, or !) → THEN do nothing.
In your first example: accidental_text = "tHIS IS A mESS"
The t is lowercase, so it flips to T.
The HIS is uppercase, so it flips to his.
The Space is not a letter, so it stays a Space.
The IS is uppercase, so it flips to is.
It knows to make IS small only because you typed it in Caps.
If you had typed is in the original string, .swapcase() would have turned it into IS.
.casefold() — The International Shield
Used for high-stakes comparisons in global software.
Global Usernames: Matching NİCK (Turkish) with nick safely.
International Search: Ensuring a German user searching for Strausse finds STRAUßE.
Reverse Engineering Signatures: Comparing byte-strings that might have varied encoding.
Spam Filters: Catching "V1AGRA" or "vIagra" using aggressive normalization.
Cross-Platform File Paths: Comparing Linux vs Windows paths which handle casing differently.
It's the Universal mode.
This is like .lower() but on steroids.
It is designed to handle non-English characters (like the German ß or Greek Σ) so that they can be compared accurately across different languages.
Real-world: If you are building a global app, always use .casefold() for search bars to ensure FLUSS matches fluß.
The Checkers (The is methods)🔍
Before you change a string, you might want to ask Python: "What is this currently?" These return True or False.
.islower(): "Is everything lowercase?"
.isupper(): "Is everything uppercase?"
.istitle(): "Is this in Title Case?"