Introduction to Python ProgrammingXYZ Homework Edition

⇩ Download ▾

1.9 Chapter summary

This chapter introduced the basics of programming in Python, including:

  • print() and input().
  • Variables and assignment.
  • Strings, integers, and floats.
  • Arithmetic, concatenation.
  • Common error messages.
  • Comments and docstrings.

At this point, you should be able to write programs that ask for input, perform simple calculations, and output the results. The programming practice below ties together most topics presented in the chapter.

Table 1.6 Chapter 1 reference.
FunctionDescription
print(values)Outputs one or more values, each separated by a space, to the user.
input(prompt)If present, prompt is output to the user. The function then reads a line of input from the user.
len(string)Returns the length (the number of characters) of a string.
type(value)Returns the type (or class) of a value. Ex: type(123) is <class 'int'>.
OperatorDescription
=
(Assignment)
Assigns (or updates) the value of a variable. In Python, variables begin to exist when assigned for the first time.
+
(Concatenation)
Appends the contents of two strings, resulting in a new string.
+
(Addition)
Adds the values of two numbers.
-
(Subtraction)
Subtracts the value of one number from another.
*
(Multiplication)
Multiplies the values of two numbers.
/
(Division)
Divides the value of one number by another.
**
(Exponentiation)
Raises a number to a power. Ex: 3**2 is three squared.
SyntaxDescription
#
(Comment)
All text is ignored from the # symbol to the end of the line.
' or "
(String)
Strings may be written using either kind of quote. Ex: 'A' and "A" represent the same string. By convention, this book uses double quotes (") for most strings.
"""
(Docstring)
Used for documentation, often in multi-line strings, to summarize a program's purpose or usage.

Adapted from Introduction to Python Programming by OpenStax (openstax.org), licensed under CC BY-NC-SA 4.0. Changes were made. License: CC-BY-NC-SA-4.0.

These eBooks are a prerelease and are not yet certified conformant with WCAG 2.1 AA or any other accessibility standard. Every page is built against an automated accessibility gate, and our target for the published editions is WCAG 2.2 Level AA. If something is unusable, please tell us.