Python – Week 2 – Built-in Data Types – Part 1

I couldn’t publish any update on programming last week as I ran into some problem with my operating system (OS). Although, Linux OS has come a long way but there still exist minor hardware-compatibility issues. Another problem was related to development environment setup.

Each time I install a package, the base system is modified, making the entire system less stable or prone to errors. Most Linux enthusiasts may agree that installing tons of packages won’t break the system but it happened with me in the past.

Upon casually browsing the Fedora website, I came across Fedora Silverblue. While going through the documentation, I learnt that it uses container system and is the perfect OS for developers. I can relate to this beautiful experience with how smartphones were pushed to innovate.

When I had Nokia N72 all I could think of at that time was a phone without keypad and a full touchscreen. I was 19 at that time and I couldn’t believe my ears when I heard Steve Jobs announced the first iPhone which was exactly how I imagined it. Fast forward to 2019 and the same history has been repeated with operating systems.

This might just be the dream operating system for developers and without second thought, I installed it. So, at the moment, I am using Fedora 30 Silverblue and I am really impressed. But, now I have a different question in my mind. Is it necessary to create a Python virtual environment inside a container using Toolbox? While I don’t have an answer to this question, I am going ahead and creating a container. Just because it sounds exciting!

Creating a container in Silverblue is much easier with Toolbox. To create one, use the following command:

toolbox create --container containername

Press y in the console if an additional file (around 500 MB) has to be downloaded. Once a container is created, enter it with:

toolbox enter --container containername

Once inside, the prompt is prepended with a diamond, confirming that you are in a container and can start creating a new development environment.

Now, I will follow the same instructions as I did in my previous blog post, which included a section on creating a virtual environment for Python development. The only difference will be the use of dnf to install packages for python development.

Integers in Python

Python supports common mathematical functions, such as addition, subtraction, multiplication, true division (returns quotient), integer division (returns floored quotient), modulo operation (returns remainder), and power operation.

>>> a = 10
>>> b = 5
>>> a + b
>>> a + b #Addition
>>> a - b #Subtraction
>>> a * b #Multiplication
>>> a / b #True Division
>>> a // b #Integer Division
>>> a % b #Modulo Operation
>>> a ** b #Power Operation


Personally, I wish life was like booleans – true or false. But, life is complicated. Anyway, back to the topic. Following examples should be enough to help you understand the concept:

>>> int(True)
>>> int(False)

The value of True and False are 1 and 0, respectively. Another interesting example can be:

>>> 1 + True
>>> 1 - True


In Python, text data is handled using str object. Here are few examples:

>>> str1 = 'My name is Tushar.'
>>> str2 = "My name will always be Tushar."
>>> str3 = '''My blog is Tushar's Blog.'''
>>> str4 = "My\nName\nis\nTushar."
>>> print(str4)

Let’s take a quick look on slicing. The general representation of slicing is any_sequence[start:stop:step]. Here are few examples:

>>> str1 = "Welcome to Tushar's Blog."
>>> str1[11:24]
"Tushar's Blog"
>>> str1[11:]
"Tushar's Blog."
>>> str1[::3]
>>> str1[::4]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s