Numbers
play an important role in our daily life either it’s about telling our age or
dealing with payments. Same goes for our programs!
In
programming, we have to deal with numbers either they are gaming scores or
storing numerical information. Python has provided us with several ways to represent
numeric data depending upon the nature of data. In the last article we have
discussed string data type and the method of string You can check the
article: https://www.codiuxtech.com/2020/12/primitive-data-types-in-python.html
Now, Let’s explore the other data types one by
one. First, we will look at how Python manages integers.
Integer:
Integers are both negative and positive whole numbers. We can add, subtract, multiply and divide the integers.
|
>>> print (3 + 4) >>> print (4 – 3) >>> print (3 * 4) >>> print (4 / 3) Output: 7 1 12 1.33 |
In python,
we need to use double multiplication signs for the exponent. Let’s take the example
below to understand it.
|
>>> print (2**3) # 2x2x2 >>> print (3**2) # 3x3 Output: 8 9 |
Note: #
symbol is used for adding comments in python
Float:
Any number
with the decimal point is called float number in python programming. Every mathematical operation that we can perform on integer can be executed on the float
as well. The float can also represent the scientific number with an “e” to express the power of 10.
|
>>> print (3.5 + 4) >>> print (4.5 – 3.5) >>> print (22e3) >>> print (-23.45e100) Output: 7.5 1.0 22000.0 -2.345e+101 |
These two
are the primitive data types of number in python. Now let’s move to the next
data type.
Boolean:
Boolean
represents either of two values: True or False.
In
programming, Booleans are used in the evaluation of an expression, comparison of
two values and return type of a function. Let’s consider the following example
to understand it:
|
>>> print (9 > 8) >>> print (3 == 2) Output: True False |
Take another
example:
|
>>> def booleanFunction() : >>> return True >>> if booleanFunction(): >>> print("YES!") >>> else: >>> print("NO!") Output: YES! |
Any string,
number, list, tuple, set and the dictionary is True except empty string, 0 and
empty list, tuple, set and dictionary.
That’s all about numbers and Boolean data type in python. If you found this article helpful share it with others. Let me know your queries and suggestions in the comment section below. Do subscribe my site and channel as I’m going to upload a series of articles and videos on programming in python and I don’t want you to miss any update.
Moreover,
you can also contact me and share your queries on Instagram, Facebook or
Twitter. I would love to provide a solution to your issues.
Stay tuned
and strive to learn. Keep learning, keep growing!

0 Comments