Today i went through something every programmer must understand deeply „data types„. Not just in theory, but to use them practically with arrays (lists) and simple logic.
so what are data types in python
In Python, I learnt that everything is an object and every object has a type.
Data types are just the “kind” of information your code is working with.
Whether it’s a name, a number, a yes/no response, or even a list of items Python wants to know: “What type of data is this?”
common data types in python
- Integer ‚int‘
This are digits. They are whole numbers either negative or positive. For example
Points=[7][5][8][6][9] #list of integers.
- Float ‚float‘
This are used to show numbers with decimal points. For example
Temperature= 36.7
3.string ’str‘
This is used in any text inside a quote. Can be a number, name or even emojis. For example
Name= "Rebecca"
4.Boolean ‚bool‘
This used in logic values. Either true or false. Suitable for conditions. For example
is-coding-cool=true
- List ‚list‘
This is just a collection of multiple items in a single variable. One can mix items too. For example
my_list = [10, "apple", True, 3.5]
print(type(my_list)) # <class 'list'>
-
Tuples ‚tuple‘
This one is the same as list but in this case can not be changed. For example
my_birthdate = (2004, 6, 23)
-
Dictionary ‚doct‘
Is just collection of key-value pairs — like mini-databases. For example
student = {"name": "Rebecca", "age": 21}
- Set ’set‘
Is an unordered collection of unique values where duplicates are ignored. For example
unique_numbers = {1, 2, 2, 3}
It gives 1,2,3 as the results
summary
What I tried
I opened my VS Code and wrote simple examples for each type.
Then printed the type using type() and played with changing values. Like
- Adding integers and floats
- Joining strings
- Creating a list of my favorite colors
4.Creating a dictionary for a student profile
It felt great seeing Python understand what I meant just by using the right type.
Thanks for reading
If you’ve just started learning Python, feel free to reach out or comment below. Let’s grow together
GitHub: Rebecca-254