- 1). Open the IDLE text editor in "Program Files" (or "Applications" for Macintosh), in the Python directory. A blank source code file opens.
- 2). Declare a variable named x and assign it the value 1. Because the value 1 has no decimal part, it becomes an integer data type. The code looks like this:
x = 1 - 3). Declare a variable named y and assign it the value 1.00. This value has a decimal component, and therefore it will be assigned the floating point data type. The code looks like this:
x = 1.00 - 4). Declare a variable named z and assign it the value 1 + 0j. Because this number has an imaginary component, the variable z is automatically created using a complex numeric type. The code looks like this:
z = 1 + 0j - 5). Print out the types of variables x, y and z by writing the following three lines of code:
print(type(x))
print(type(y))
print(type(z)) - 6). Execute the script by pressing "F5." The program output looks like this:
<class 'int'>
<class 'float'>
<class 'complex'>
SHARE