In Python there are 5 basic types: Integers, Floating-Point Numbers, Complex Numbers, Strings and Boolean.
Before I explain how to create and use the basic types in Python, note that Python is dynamic language unlike java and c# which are static languages. It means that variables need not be declared or defined. To create a variable, you just assign it a value and then start using it. Assignment is done with a single equals sign (=).
inttype in Python designates an integer number.
num1 = 3
--> print(num1 + 1)
- Floating-Point Numbers
floattype in Python designates a floating-point number. float values are specified with a decimal point. Optionally, the character
Efollowed by a positive or negative integer may be appended to specify scientific notation.
num2 = 3.5
num3 = 4e7
--> print(num3 + 1)
- Complex Numbers
complextype in Python designates a complex number. Complex numbers are specified as
<real part> + <imaginary part>j
num4 = 2+3j
--> print(num4 + 1 + 1j)
strtype in Python designates a string. A string is a sequence of characters that is delimited by single or double quotes.
str = "Hello World"
--> print(str + ", Tomer")
Hello World, Tomer
booltype in Python designates a boolean. Variables of Boolean type may have one of two values:
bool = True