liveBook · Manning

Numeric base

As explained in Python Workout, Second Edition

A number base is the radix that determines the positional values of digits in a numeral system.

A numeric base determines how Python interprets digit characters when converting a string to an integer. Pass the base as int’s optional second argument. section 2.15

The same input, different bases

The string "10" can represent different values: int("10", 2) interprets it as 2, while int("10", 16) interprets it as 16. A hexadecimal conversion therefore passes 16 explicitly. section 2.15 section 2.5

Use numeric bases as practice problems:

  • Extend a guessing game so each round selects a random base from 2 through 16 and interprets the user’s input accordingly. section 2.5
  • Reimplement conversion without int, using ord and chr to recognize legal characters for the selected base. section 2.17

How Python Workout, Second Edition covers it

How deep it goes
Explains int’s base argument and practices bases 2–16, without detailing numeral-system internals.
Examples
Uses hexadecimal conversion and a guessing game that accepts numbers in randomly selected bases.
What it assumes
Builds from string input and integer conversion, then extends practice through loops and character functions.
What you can do after
Apply it via Python’s int function to interpret user-entered strings in a specified base.
How it connects
Connects numeric bases with string input, integer conversion, guessing games, and character handling through ord and chr.

Also explained in

Compare how 2 books explain numeric base →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Python Workout, Second Edition. The section links point to the parts of the book it draws on.