There are different categories of data. For instance, think about the data on an ID card. The card has numbers to store weight, height, date of birth, street address, and postal code. It has words to store a person’s name and city. There’s also image data (a photo), and often an organ donor choice, which is a yes/no decision. In Processing, we have different data types to store each kind of data. Each of the following types is explained in more detail elsewhere in the book, but this is a summary:
Name | Description |
---|---|
|
Integers (whole numbers) |
|
Floating-point values |
|
Logical value |
|
Sequence of characters |
|
PNG, JPG, or GIF image |
|
Use the |
|
SVG file |
As a guideline, a float
number has about four digits of accuracy after the decimal point. If you’re counting or taking small steps, you should use an int
value to take the steps, and then perhaps scale it by a float
if necessary when putting it to use.
Python automatically determines the data type of a value when you first create it. You can use the built-in type()
function to check the type of a value or variable. This can be helpful when debugging. For example:
x
=
10
type
(
x
)
# prints <type 'int'>
y
=
17.4
type
(
y
)
# prints <type 'float'>
There are more data types than those mentioned here, but these are the most useful for the work typically made with Processing. In fact, as mentioned in Chapter 10, there are infinite types of data, because every new class is a different data type.
3.144.19.243