Login
📚 Introduction to Python Programming
Chapters ▾

2.9 Chapter summary

Highlights from this chapter include:

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

Table 2.10 Chapter 2 reference.
FunctionDescription
abs(x)Returns the absolute value of x.
int(x)Converts x (a string or float) to an integer.
float(x)Converts x (a string or integer) to a float.
str(x)Converts x (a float or integer) to a string.
round(x, ndigits)Rounds x to ndigits places after the decimal point. If ndigits is omitted, returns the nearest integer to x.
OperatorDescription
s * n
(Repetition)
Creates a string with n copies of s. Ex: "Ha" * 3 is "HaHaHa".
x / y
(Real division)
Divides x by y and returns the entire result as a float. Ex: 7 / 4 is 1.75.
x // y
(Floor division)
Divides x by y and returns the quotient as an integer. Ex: 7 // 4 is 1.
x % y
(Modulo)
Divides x by y and returns the remainder as an integer. Ex: 7 % 4 is 3.