Datatypes
Datatypes
O Level / A Level
Data Types
The data stored in memory can be of many types. For example, a person's age is stored as a
numeric value and his or her address is stored as alphanumeric characters. Python has various
standard data types that are used to define the operations possible on them and the storage
method for each of them. Variables can store data of different types, and different types can do
different things.
Python has the following data types built-in by default, in these categories:
Example Integers:
x=1
y = 35656222554887711
z = -3255522
Float
Float, or "floating point number" is a number, positive or negative, containing one or more
decimals.
Example Floats:
x = 1.10
y = 1.0
z = -35.59
Float can also be scientific numbers with an "e" to indicate the power of 10.
Example Floats:
x = 35e3
y = 12E4
z = -87.7e100
Complex
Complex numbers are written with a "j" as the imaginary part:
Example Complex:
x = 3+5j
y = 5j
z = -5j
Type Conversion
We can convert from one type to another with the int(), float(), and complex() methods:
Example
print(a)
print(b)
print(c)
print(type(a))
print(type(b))
print(type(c))