liveBook · Manning

Unit type

As explained in Get Programming: Learn to code with Python

An empty tuple is a tuple containing no elements.

An empty tuple is a tuple containing no elements. In Python, write it as (). Tuples can hold sequences of objects, and an empty tuple gives you a clear starting value for a collection that will grow as the program finds results. section 10.1 section 19.2

Starting a word collection

In the Scrabble program, all_valid_words = () and found_words = () create two empty tuples. The program later adds each discovered word by concatenating a one-item tuple, such as (word,), to the existing tuple. section 19.2

Listing 19.1. Scrabble: Art Edition code for initializations
words = """art                      #1
hue
ink
...
crosshatching
"""
tiles = "hijklmnop"

all_valid_words = ()                #2
start = 0                           #3
end = 0                             #4
found_words = ()                    #5

See the initialization listing where empty tuples establish the starting collections for valid words and found words. section 19.2

Keep these tuple forms distinct:

  • () contains no objects, while (word,) contains one object. The comma identifies a singleton tuple. section 10.1
  • Use parentheses and commas to represent tuples containing different kinds of objects, including nested tuples. section 10.1

How Get Programming: Learn to code with Python covers it

How deep it goes
Defines empty and singleton tuple syntax, then demonstrates initialization and concatenation without exploring tuple internals.
Examples
Demonstrates all_valid_words = (), found_words = (), and adding discovered words with singleton tuples.
What it assumes
Assumes basic Python assignment and introduces tuple notation, empty tuples, singleton tuples, and tuple contents.
What you can do after
Build it from scratch by initializing tuple collections and extending them with concatenated singleton tuples.
How it connects
Connects empty tuples with tuples, sequences, string processing, concatenation, and collections of discovered words.

Also explained in

Compare how 7 books explain unit type →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Get Programming: Learn to code with Python. The section links point to the parts of the book it draws on.