June 2002
Beginner to intermediate
640 pages
14h 24m
English
You can determine a type at runtime with the built-in type() function along with the Python types module, which defines all of the basic types.
First, we import the types module and create some variables from all of the basic types.
>>> from types import * >>> int = 1 #holds a integer >>> float = 1.0 #holds a float >>> long = 1L #holds a long >>> string = "string" #holds a string
Now we test to see if the variable string is of type String. Here we'll be using the if statement, which works like if in other languages. Just remember that if's subordinate statements must be indented. (We'll be covering this in Chapter 4.)
The ... prompt tells you to enter the subordinate statement, print. Make sure to ...
Read now
Unlock full access