Variables and Basic Types

In this chapter, we will present the most important and basic types in Python. What is a type? It is a set consisting of data content, its representation, and all possible operations. Later in this book, we will make this definition much more precise when we introduce the concepts of a class in Chapter 8: Classes.

In this chapter, we'll cover the following topics:

  • Variables
  • Numeric types
  • Booleans
  • Strings

2.1 Variables

Variables are references to Python objects. They are created by assignments, for example:

a = 1diameter = 3.height = 5.cylinder = [diameter, height] # reference to a list

Variables take names that consist of any combination of capital and small letters, the underscore _, and digits. A variable name ...

Get Scientific Computing with Python - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.