If you are a beginner in Python, you should start by learning data types. You should start learning what is a data type in Python. It is crucial to understand and learn deeply about what kind of data types Python has. I will try to explain as simple as possible, so, even if you are a complete beginner you will be able to understand. If you are not a beginner but still want to refresh your knowledge, please keep reading.
Note 1: When you see “>>>” you should not type it to python. I am using it as a reference that you need to type a command. Besides, I made all commands in red for your easier reference.
Note 2: For your easier reference, I marked all outputs as blue.
Note 3: Do not copy-paste code. If you copy, you will not have practice. You are here to learn, so type it. You will get practice and you will not forget codes.
Note 4: If you have any suggestions, please comment below.
Note 5: For easier learning, I recommend using a jupyter notebook. It is free and lightweight.
What is the data type? We can call data types in Python as a value categorization or classification. What do I mean by that? When you have a value, Python wants to know which operations can be done by the value. Don´t worry, Python is smart enough to understand most of the time.
I will also try to give some coding examples. Therefore, by the end of this article, you will be more familiar with what data types are and how they are represented.
Before I start, I would like to introduce you to two commands. With these commands, you will be able to understand this article better.
The first command is “print()”. This command lets you print the data between parentheses. Let´s see how to use it.
>>>Print("I am new to Python")
When you type this to python and run, you will get a response like this
I am new to Python
The second command is “type()”. This command will tell you the data type of the data you placed between parentheses. Let´s see how to use it.
Code:
>>>type("This is a data")
Output:
<class 'str'>
If it is confusing, don´t worry. We will use this command for each data type.