liveBook · Manning

Empty string

As explained in Tiny Python Projects: Learn coding and testing with puzzles and games

An empty string is a string value containing no characters.

An empty string is a string value containing no characters. Write it as '' and use it as a starting value when building text incrementally. section 4.4.3 section 2.1.11

Build transformed text

Start with new_text = ''. For each character, append either its mapped replacement or the original character with +=. Printing the completed value produces ABC987. section 4.4.3

def main():
    args = get_args()
    jumper = {'1': '9', '2': '8', '3': '7', '4': '6', '5': '0',
              '6': '4', '7': '3', '8': '2', '9': '1', '0': '5'}
    new_text = ''                                                #1
    for char in args.text:                                       #2
        new_text += jumper.get(char, char)                       #3
    print(new_text)                                              #4

A complete function shows the empty string as an accumulator before a loop transforms each input character. section 4.4.3

How Tiny Python Projects: Learn coding and testing with puzzles and games covers it

How deep it goes
Defines the value and demonstrates initialization, concatenation, and output control, but does not examine string internals.
Examples
Demonstrates text transformation, article selection, and verse generation using empty strings or lists as initial accumulators.
What it assumes
Assumes basic Python variables, strings, loops, and conditionals while demonstrating empty-value initialization directly.
What you can do after
Apply empty strings to build text incrementally and control print() endings in Python programs.
How it connects
Connects empty strings with strings, loops, concatenation, conditionals, list comprehensions, and map().

Also explained in

Compare how 3 books explain empty string →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny Python Projects: Learn coding and testing with puzzles and games. The section links point to the parts of the book it draws on.