🎓 EASYTUTORGUIDE · Complete Python Course

Very beginner → professional Python · 60 chapters · 900 topics

EasyTutorGuide

Chapter 9: String Formatting and Methods

Complete Python lesson for very beginners. Technical words are explained in simple language, and every outline topic includes a practical example, expected output, steps, and practice.

Python CourseVery Beginner Friendly15 TopicsExamples + Output20 Q&A
Chapter 9 · 15 topics
100%

Chapter Overview

This Python tutorial chapter covers String Formatting and Methods through 15 connected topics. Work through the examples in order, check the expected output, and complete the practice after each topic.

  • 9.1 f-Strings
  • 9.2 format()
  • 9.3 Format Specifications
  • 9.4 Alignment
  • 9.5 Number Formatting
  • Plus 10 additional Python topics in this chapter.

9.1 f-Strings

f-Strings is part of String Formatting and Methods. In simple language, it means text stored as characters.

It is one building block of string formatting and methods and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: f-Strings (text stored as characters).

Python / Practical Example

name = "Ava"
score = 92
print(f"{name} scored {score}%")

Expected Output

Ava scored 92%

Step-by-Step Explanation

  1. Put f before the string.
  2. Place expressions inside braces.
  3. Python inserts their values into the text.
Practice: Re-type the example for “f-Strings”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

9.2 format()

format() is part of String Formatting and Methods. In simple language, it means a Python idea used while learning string formatting and methods.

It is one building block of string formatting and methods and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: format() (a Python idea used while learning string formatting and methods).

Python / Practical Example

name = "Ava"
print(f"Hello {name}")

Expected Output

Hello Ava

Step-by-Step Explanation

  1. Read the example from top to bottom.
  2. Identify the value, object, or operation related to this topic.
  3. Change one small input and predict the result before running it.
Practice: Re-type the example for “format()”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

9.3 Format Specifications

Format Specifications is part of String Formatting and Methods. In simple language, it means a Python idea used while learning string formatting and methods.

It is one building block of string formatting and methods and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Format Specifications (a Python idea used while learning string formatting and methods).

Python / Practical Example

name = "Ava"
print(f"Hello {name}")

Expected Output

Hello Ava

Step-by-Step Explanation

  1. Read the example from top to bottom.
  2. Identify the value, object, or operation related to this topic.
  3. Change one small input and predict the result before running it.
Practice: Re-type the example for “Format Specifications”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

9.4 Alignment

Alignment is part of String Formatting and Methods. In simple language, it means a Python idea used while learning string formatting and methods.

It is one building block of string formatting and methods and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Alignment (a Python idea used while learning string formatting and methods).

Python / Practical Example

name = "Ava"
print(f"Hello {name}")

Expected Output

Hello Ava

Step-by-Step Explanation

  1. Read the example from top to bottom.
  2. Identify the value, object, or operation related to this topic.
  3. Change one small input and predict the result before running it.
Practice: Re-type the example for “Alignment”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

9.5 Number Formatting

Number Formatting is part of String Formatting and Methods. In simple language, it means a Python idea used while learning string formatting and methods.

It is one building block of string formatting and methods and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Number Formatting (a Python idea used while learning string formatting and methods).

Python / Practical Example

name = "Ava"
print(f"Hello {name}")

Expected Output

Hello Ava

Step-by-Step Explanation

  1. Read the example from top to bottom.
  2. Identify the value, object, or operation related to this topic.
  3. Change one small input and predict the result before running it.
Practice: Re-type the example for “Number Formatting”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

9.6 upper() and lower()

upper() and lower() is part of String Formatting and Methods. In simple language, it means a Python idea used while learning string formatting and methods.

It is one building block of string formatting and methods and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: upper() and lower() (a Python idea used while learning string formatting and methods).

Python / Practical Example

text = "Python"
print(text.upper())
print(text.lower())

Expected Output

PYTHON
python

Step-by-Step Explanation

  1. String methods return new strings.
  2. upper() capitalizes letters.
  3. lower() makes letters lowercase.
Practice: Re-type the example for “upper() and lower()”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

9.7 strip()

strip() is part of String Formatting and Methods. In simple language, it means a Python idea used while learning string formatting and methods.

It is one building block of string formatting and methods and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: strip() (a Python idea used while learning string formatting and methods).

Python / Practical Example

text = "  hello  "
print(text.strip())

Expected Output

hello

Step-by-Step Explanation

  1. The original string contains surrounding spaces.
  2. strip() removes leading and trailing whitespace.
  3. The middle text remains.
Practice: Re-type the example for “strip()”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

9.8 split()

split() is part of String Formatting and Methods. In simple language, it means a Python idea used while learning string formatting and methods.

It is one building block of string formatting and methods and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: split() (a Python idea used while learning string formatting and methods).

Python / Practical Example

text = "red,blue,green"
print(text.split(","))

Expected Output

['red', 'blue', 'green']

Step-by-Step Explanation

  1. Choose a delimiter.
  2. split() breaks the string at that delimiter.
  3. The result is a list of strings.
Practice: Re-type the example for “split()”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

9.9 join()

join() is part of String Formatting and Methods. In simple language, it means a Python idea used while learning string formatting and methods.

It is one building block of string formatting and methods and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: join() (a Python idea used while learning string formatting and methods).

Python / Practical Example

parts = ["2026", "09", "21"]
print("-".join(parts))

Expected Output

2026-09-21

Step-by-Step Explanation

  1. Start with strings in a list.
  2. Call join() on the separator.
  3. A single combined string is returned.
Practice: Re-type the example for “join()”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

9.10 replace()

replace() is part of String Formatting and Methods. In simple language, it means a Python idea used while learning string formatting and methods.

It is one building block of string formatting and methods and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: replace() (a Python idea used while learning string formatting and methods).

Python / Practical Example

text = "I like cats"
print(text.replace("cats", "Python"))

Expected Output

I like Python

Step-by-Step Explanation

  1. replace() searches for matching text.
  2. It returns a new string with replacements.
  3. The original string is unchanged.
Practice: Re-type the example for “replace()”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

9.11 find()

find() is part of String Formatting and Methods. In simple language, it means a Python idea used while learning string formatting and methods.

It is one building block of string formatting and methods and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: find() (a Python idea used while learning string formatting and methods).

Python / Practical Example

text = "learn Python"
print(text.find("Python"))

Expected Output

6

Step-by-Step Explanation

  1. find() searches for a substring.
  2. It returns the starting index.
  3. If the text is not found, it returns -1.
Practice: Re-type the example for “find()”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

9.12 startswith() and endswith()

startswith() and endswith() is part of String Formatting and Methods. In simple language, it means a Python idea used while learning string formatting and methods.

It is one building block of string formatting and methods and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: startswith() and endswith() (a Python idea used while learning string formatting and methods).

Python / Practical Example

name = "report.csv"
print(name.startswith("rep"))
print(name.endswith(".csv"))

Expected Output

True
True

Step-by-Step Explanation

  1. startswith() checks the beginning.
  2. endswith() checks the ending.
  3. Both return boolean results.
Practice: Re-type the example for “startswith() and endswith()”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

9.13 Character Testing Methods

Character Testing Methods is part of String Formatting and Methods. In simple language, it means a function associated with an object or class.

It makes programs easier to trust, diagnose, change, and maintain as they become larger. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Character Testing Methods (a function associated with an object or class).

Python / Practical Example

import unittest

def add(a, b): return a + b

class AddTest(unittest.TestCase):
    def test_add(self):
        self.assertEqual(add(2, 3), 5)

result = unittest.TextTestRunner(verbosity=0).run(unittest.defaultTestLoader.loadTestsFromTestCase(AddTest))
print(result.wasSuccessful())

Expected Output

True

Step-by-Step Explanation

  1. Define behavior to test.
  2. Create a TestCase method whose name begins with test.
  3. Run the test and check that it succeeds.
Practice: Re-type the example for “Character Testing Methods”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

9.14 Encoding and Decoding

Encoding and Decoding is part of String Formatting and Methods. In simple language, it means rules for converting text characters to and from bytes.

It is one building block of string formatting and methods and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Encoding and Decoding (rules for converting text characters to and from bytes).

Python / Practical Example

name = "Ava"
print(f"Hello {name}")

Expected Output

Hello Ava

Step-by-Step Explanation

  1. Read the example from top to bottom.
  2. Identify the value, object, or operation related to this topic.
  3. Change one small input and predict the result before running it.
Practice: Re-type the example for “Encoding and Decoding”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

9.15 Practical Text Processing

Practical Text Processing is part of String Formatting and Methods. In simple language, it means a running program with its own process resources.

It is one building block of string formatting and methods and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Practical Text Processing (a running program with its own process resources).

Python / Practical Example

from multiprocessing import cpu_count
print(cpu_count() >= 1)

Expected Output

True

Step-by-Step Explanation

  1. multiprocessing provides process-based parallelism tools.
  2. cpu_count() reports available logical CPUs as seen by Python.
  3. Process-based work has communication and startup costs.
Practice: Re-type the example for “Practical Text Processing”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

Common Beginner Mistakes

  • Copying code without predicting what each line does.
  • Ignoring the first useful error message or traceback location.
  • Mixing tabs/spaces or changing indentation accidentally.
  • Using data of the wrong type for an operation.
  • Trying to learn many advanced variations before mastering one small working example.

Chapter Practice

  1. Choose three topics from this chapter and re-type their examples without copying and pasting.
  2. For each example, change one input and predict the output first.
  3. Explain five technical terms from this chapter in your own beginner-friendly words.
  4. Create one small program that combines at least two chapter topics.
  5. Keep notes about errors you made and what fixed them.

Mini Project / Challenge

Create a small Python exercise that combines at least three ideas from String Formatting and Methods. Start with a tiny working version, test it, then improve it one step at a time.

  1. Choose three topics from this chapter.
  2. Write or adapt a small Python example using those topics.
  3. Predict the output before running the code.
  4. Test at least one different input.
  5. Write two sentences explaining what the program does and what you learned.

20 Questions & Answers

1. What is the main goal of Chapter 9?

The goal is to understand string formatting and methods through small explanations, examples, and practice.

2. Should I memorize every command or method?

No. Understand the pattern, practice the common form, and learn how to read documentation when you need exact details.

3. Why are the examples small?

Small examples isolate one idea at a time, which makes errors easier to understand and fix.

4. What should I do when an example gives an error?

Read the last part of the traceback, check spelling and indentation, confirm the required package or file exists, and compare the input types with what the operation expects.

5. Why should I predict output before running code?

Prediction forces you to reason about the program instead of only copying it.

6. What should I remember about f-Strings?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

7. What should I remember about format()?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

8. What should I remember about Format Specifications?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

9. What should I remember about Alignment?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

10. What should I remember about Number Formatting?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

11. What should I remember about upper() and lower()?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

12. What should I remember about strip()?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

13. What should I remember about split()?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

14. What should I remember about join()?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

15. What should I remember about replace()?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

16. What should I remember about find()?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

17. What should I remember about startswith() and endswith()?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

18. What should I remember about Character Testing Methods?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

19. What should I remember about Encoding and Decoding?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

20. What should I remember about Practical Text Processing?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.