liveBook · Manning

Value

As explained in Get Programming: Learn to code with Python

A concrete item of data representing a result, state, or piece of information in a program.

A value is a concrete piece of data in a program. Numbers, strings, and Boolean results are values. An object has a value, and an expression is code that can be reduced to one value. section 4.3 section 5.3

Values appear in several closely related programming ideas:

  • A variable is a name bound to an object, whose value can be used later. section 4.3
  • An expression such as 3 + 2 produces the value 5; assignment and printing are statements, not expressions. section 5.3
  • A dictionary stores key-value pairs, where a key identifies the value returned by a lookup. section 27.1
  • A dictionary value can itself be one object, such as a tuple or a list of grades. section 27.1 section 27.4

Values in a grocery dictionary

grocery = {"milk": 1, "eggs": 12, "bread": 2} Here, "milk", "eggs", and "bread" are keys. The values 1, 12, and 2 record each quantity. Looking up a key retrieves its corresponding value. section 27.1

Listing 27.3. Keeping track of student grades by using a dictionary
grades = {}                                    #1
grades["Chris"] = [100, 70]                    #1
grades["Angela"] = [90, 100]                   #1
grades["Bruce"] = [80, 40]                     #1
grades["Stacey"] = [70, 70]                    #1

for student in grades.keys():                  #2
    print(student)                             #2

for quizzes in grades.values():                #3
    print(sum(quizzes)/2)                      #2

for student in grades.keys():                  #4
    scores = grades[student]                   #5
    grades[student].append(sum(scores)/2)      #6
print(grades)                                  #7

Trace how a dictionary stores student grade lists, reads values with a loop, calculates averages, and appends new values. section 27.4

How Get Programming: Learn to code with Python covers it

How deep it goes
Defines values through expressions and data structures, but stops short of implementation internals.
Examples
Uses arithmetic results, grocery quantities, song ratings, student grades, and hour-to-minute conversion outputs.
What it assumes
Assumes basic Python interaction while teaching objects, expressions, variables, and values from foundational examples.
What you can do after
Evaluate/understand how Python expressions produce values and how dictionaries store, retrieve, iterate over, and modify them.
How it connects
Connects values with objects, variables, expressions, statements, dictionaries, keys, tuples, lists, and data types.

Also explained in

Compare how 7 books explain value →

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.