Data types in Python

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

Data types are an essential aspect of a programming language. As it comes down to Python there are several categorized data types built-in that we can leverage.
This article will guide you through the categories and which type each category has.
This guide will show you the basics of each. I will do a more detailed guide on some of these.
As it comes to string in Python, there is only one option: the str.
As single or double quotes define string as we can see here:
foo = "String"
bar = 'string'
Both variables will hold the exact same string.
With numeric types, there is three built-in option we can leverage.
int, float, complex
I'll first show you what they look like:
a = 1 # Int
b = 3.14 # Float
c = 1j # Complex
Integers can be numbers of any length, and they can even be negative. The only thing is they can't have decimals.
Some examples of different int in Python.
a = 1
b = 83458903489734890
c = -2323434
As for a float, this again is a number, but it can hold decimals.
a = 3.14
b = 1.0
c = -40.53
The complex to me is a new addition in programming, and it can define an imaginary part defined by the letter j.
a = 1+2j
b = 5j
c = -3j
Sequence types are sets of data. See them as arrays or objects.
There are four basic types we can use.
list, tuple, set, range
I'll show you the basics of each sequence.
The list can be used to store multiple items in a single variable. These are generally compared to arrays.
list = ["dog", "cat", "penguin"]
The list can store data, change, add or remove.
Tuples, however, can't be changed. This is the main difference from lists. Tuples are also created by using regular brackets.
tuple = ("dog", "cat", "penguin")
A set is unordered and unindexed, meaning it can't contain multiple of the same entry. Curly brackets define a set.
set = {"dog", "cat", "penguin"}
Then there is also the range option which allows us to create a range of numbers.
a = range(6)
This will give us a range from 0-6.
There is another sequence type, but it falls under a mapping type, and it's the dict one.
Dictionaries are used to store data as a key-value pair.
Dict = {
"type": "pet",
"animal": "dog",
"name": "Yaatree"
}
A dictionary is changeable, so items can be removed, added, or changed.
We can, however, not have duplicates in a dict.
As for the boolean, which we know holds a true/false statement can be used as the bool variable.
For instance, we can check random values for True or False.
bool(False) # False
bool("a") # True
bool({}) # False
bool(123) # True
bool(0) # False
bool(10 > 9) # True
These are the basic built-in data types of Python you need to know when getting started with Python.
I would strongly suggest creating some basic Python script to run these and have a play around with.
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter