In Python, like every other programing language as well, you can define different types of objects. This is necessary and helpful in many aspects. Through those object the computer understands what the programer or engineer what’s it to do. It can even help to optimize the performance of the program.
People who beginn with programing often don’t understand the concept of the different object types or simply forget that the definition of an object type, resulting in an error message.
In the following lines, I explain the basic object types and how they are used.
In Python are three basic numeric types:
With numeric types a computer can work and calculate.
A number of the type integer (or int) is defined as a whole number without a decimal point. It can be positive or negative.
They are usually used for simple operations or just to count iterations. To convert a number or input as an int, you need to define it like this:
a = int(13). Now the computer knows the variable
a in an integer with the value „13“.
Another type is the float (or floating points numbers). They can be negative and positive as well.
They are used when you need to quantify something precisely. Especially after dividing two numbers it is not unusual that you end up with a number with a decimal point. But a float can also be a whole number:
With the function
b = float(4) you can define that the variable
b should be a float. And by the way, with
print(type(b)) you can print out the type of a variable (in this case the type of
Now, complex numbers are of the form a + bJ, where a and b are floats and J (or j) represents the square root of -1 (which is an imaginary number). The real part of the number is a, and the imaginary part is b. Complex numbers are not used much in Python programming.
String are sequences of digits or characters. They can consist of numeric characters or letters. Also strings are immortal, what means that you can’t change theme once they are defined. Functions like
split() do not really change the string itself but create a copy of the string and manipulate the copy.
Also, when defining the vales and characters in a string, it is important to put the value in single quotes (
' ') or double quotes (
" "). There is no difference between them in this context.
The last type I want to show are tuples. A Tuple is a collection of Python objects separated by commas. In someways a tuple is similar to a list in terms of indexing, nested objects and repetition but a tuple is immutable unlike lists which are mutable.The last type I want to show are tuples.
In the example above it shows, that
j are tuples (
)) method proves it). All values in the tuple can be given printed and used. And it is possible to print one single value of a tuple. Therefore you need to write the position of the needed value in squared brackets (
[ ] ). Don’t forget that the count starts with zero (0).
Those are the most important types you need to know in Python. Of course this list is not final.