Skip to ContentGo to accessibility pageKeyboard shortcuts menu
OpenStax Logo

Grace Murray Hopper at the UNIVAC keyboard
Figure 2.1 credit: modification of work "Grace Hopper at Univac I console", courtesy of the Computer History Museum

A computer program is a sequence of statements that run one after the other. In Python, many statements consist of one or more expressions. An expression represents a single value to be computed. Ex: The expression 3*x - 5 evaluates to 7 when x is 4. Learning to recognize expressions opens the door for programming all kinds of interesting calculations.

Expressions are often a combination of literals, variables, and operators. In the previous example, 3 and 5 are literals, x is a variable, and * and - are operators. Expressions can be arbitrarily long, consisting of many calculations. Expressions can also be as short as one value. Ex: In the assignment statement x = 5, the literal 5 is an expression.

The Statements chapter introduced simple expressions like 1 * 2 and "Hi " + "there". This chapter explores other kinds of expressions for working with numbers and strings. The first section shows a great way to experiment with expressions using a Python shell. Later sections present more details about integers and floating-point numbers, explain how to import and use the math module, and show how to make long lines of code easier to read.

Citation/Attribution

This book may not be used in the training of large language models or otherwise be ingested into large language models or generative AI offerings without OpenStax's permission.

Want to cite, share, or modify this book? This book uses the Creative Commons Attribution License and you must attribute OpenStax.

Attribution information
  • If you are redistributing all or part of this book in a print format, then you must include on every physical page the following attribution:
    Access for free at https://openstax.org/books/introduction-python-programming/pages/1-introduction
  • If you are redistributing all or part of this book in a digital format, then you must include on every digital page view the following attribution:
    Access for free at https://openstax.org/books/introduction-python-programming/pages/1-introduction
Citation information

© Jul 30, 2024 OpenStax. Textbook content produced by OpenStax is licensed under a Creative Commons Attribution License . The OpenStax name, OpenStax logo, OpenStax book covers, OpenStax CNX name, and OpenStax CNX logo are not subject to the Creative Commons license and may not be reproduced without the prior and express written consent of Rice University.

This book utilizes the OpenStax Python Code Runner. The code runner is developed by Wiley and is All Rights Reserved.