Practical Implementation of Primitive Datatype in one of the Python IDEs, Jupyter Notebook #Part-1

kanak Gupta Mar 25 2021 · 1 min read
Share this

1. Integer Data Type:  In this type, we take up the whole number, and it can be of any length

Input

#Integer values always take whole values

value_1 = int(input('Enter first whole number:'))

value_2 = int(input('Enter second whole number:'))

add = value_1 + value_2

# print() gives permanent output

print('Addition of 2 integer value {} and {} is {}'.format(value_1,value_2,add))

#  type() tells in which class a variable belongs to

print(add,'is type of', type(add))

Output

Enter first whole number:8500

Enter second whole number:1200

The addition of 2 integer value 8500 and 1200 is 9700

9700 is type of <class 'int'>

2. Float data type - In this type, we take up decimal values and give accurate values up to 15 decimal places.

Input

a = 12.1564897123654789

print(a,'is a decimal value upto place 15')

print(a,'is a type of',type(a))

# isinstance() tells particular value belongs to that class or not

print(a,'is float number? ',isinstance(a,float))

Output

12.15648971236548 is a decimal value up to place 15

12.15648971236548 is a type of <class 'float'>

12.15648971236548 is the float number? True

we can see in our float number as 9 is truncated

3. Complex Data type: Complex numbers make with the real and the imaginary parts i.e a+bj. For the imaginary part, we use 'j' in python.

Input

num = 12 + 4j

print(num,'is belong to',type(num))

print(num,'is a complex number?', isinstance(num,complex))

Output

(12+4j) is belong to <class 'complex'>

(12+4j) is a complex number? True

4. Boolean Data Type: It always takes up True(1) or False(0) values and gives output either 1 or 0. Let's see by the example

Input

a = True

b = False

print(a,b,'belong to',type(a),type(b))

print('sum and multiplication of boolean values {},{} are : '.format(a,b),a+b,'and',a*b)

print('Type of sum and multiplication is',type(a+b),type(a*b))

Output

True False belong to <class 'bool'> <class 'bool'>

sum and multiplication of boolean values True,False are : 1 and 0

Type of sum and multiplication is <class 'int'> <class 'int'>

here we can see class of sum and multiplication is integer.

5. String Data Type: String literals can be defined with any of single quotes ('), double quotes (") or triple quotes (''' or """). All give the same result with two important differences.

If you quote with single quotes, you do not have to escape double quotes and vice-versa. If you quote with triple quotes, your string can span multiple lines

Input

string = 'Hello Python'

print(string,'belongs to',type(string))

# Parsing the string by using index number

print('First letter of word =',string[0])

#start(0) :end(5-1) : step size(2) always exclude upper bound means gives output till index no:UB-1

print('Desired result with step size 2 =',string[0:5:2])

# Reverse the string

print('Reverse the given string = ', string[::-1])

# multiple lines

"""print("fsdfsdfs)

(FsdfsfsFSDFSAFASFASDDF)

(sdfsfsdf")"""

Output

Hello Python belongs to <class 'str'>

The first letter of word = H

The desired result with step size 2 = Hlo

Reverse the given string = nohtyP olleH

'print("fsdfsdfs)\n(FsdfsfsFSDFSAFASFASDDF)\n(sdfsfsdf")'

Comments
Read next