Appendix B. Data Types

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

int

Integers (whole numbers)

float

Floating-point values

bool

Logical value

str

Sequence of characters

PImage

PNG, JPG, or GIF image

PFont

Use the createFont() function or the Create Font tool to make fonts to use with Processing

PShape

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
print type(x) # prints <type 'int'>
y = 17.4
print 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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.159.223