Module 3: Python StringsBeginner16 min read
String Formatting & Methods
Explore f-strings, format(), and built-in string methods like split, join, strip.
Key Takeaways & Core Concepts
.upper()/.lower(): Convert case.strip(): Remove leading/trailing whitespace.replace(old, new): Replace occurrences of substring.split(delimiter): Split string into a list of strings
String Formatting & Methods
### Python String Methods & F-Strings
Python provides a rich set of built-in methods for working with textual data.
#### Common String Methods:
.upper()/.lower(): Convert case.strip(): Remove leading/trailing whitespace.replace(old, new): Replace occurrences of substring.split(delimiter): Split string into a list of stringsdelimiter.join(list): Join iterable items into a single string.startswith(prefix)/.endswith(suffix): Boolean prefix/suffix check
#### Modern F-Strings (Python 3.6+) F-strings provide the most readable, concise way to format values directly into strings:
PYTHON Code Example
1course = "Python Masterclass"
2price = 4999.50
3students = 12500
4
5message = f"Course: {course} | Price: ₹{price:,.2f} | Students: {students:,}"
6print(message)
Click code or "Edit Code" to edit
Interactive Code Block•Tab = 4 spaces•Ctrl + Enter = Run
6 lines
Clean and Parse CSV Line
1raw_data = " laptop, Dell XPS 15, 125000 "
2cleaned = [item.strip() for item in raw_data.split(",")]
3print("Cleaned List:", cleaned)
Click code or "Edit Code" to edit
Interactive Code Block•Tab = 4 spaces•Ctrl + Enter = Run
3 lines
Note: split(',') splits on commas, and strip() trims unnecessary surrounding spaces.
Practice & AssessmentPython Programming Tutorial
Test Your Understanding
Reinforce core concepts with interactive multiple-choice questions, live coding challenges, and top technical interview questions.
Your Current Score
0 / 0 correct(0 attempted)