Home / Computer Science / Python / Basic Data Types in Python

Basic Data Types in Python

Like other programming languages python has multiple data types to handle programming scenarios.

These data types are builtin data types. Basic data types available in Python are listed below.

  1. Boolean
  2. Integer
  3. Complex
  4. Float
  5. String
Data Type Symbol Notes Value Range
Boolean bool Boolean data type uses when we represent conditional statements or logic statements like true or false True or False
Integer int Integer data type represents both positive and negative data type values all integers (+ve and -ve)or set ‘Z
Complex complex If you want to deal with complex numbers such contains real and imaginary parts (x + iy) where x is real and iy is imaginary part All complex number in the form of x + iy
Float float A number which contains decimals are declared as floating point numbers All decimal numbers
String str All the string which are enclosed in the single ” ‘ ” quote or double ” ” ” quotes are treated as strings, even if the number is present in these quotes treated as string. Strings or a sequence of characters

The above table shows basic data types and its symbols.

In my previous post, you may learn how to find the data type of the variable.

Here is the demo program for your reference.


# -*- coding: utf-8 -*-
"""
Created on Tue Oct 29 00:08:28 2019

@author: GSK
"""
a = "Hello Python"

#To display value of a:
print(a)

#to know the data type of a:
print(type(a))

b = 52

#To display value of b:
print(b)

#to know the data type of b:
print(type(b))

c = 20.5

#To display value of c:
print(c)

#to know the data type of c:
print(type(c))

d = complex(2,1)

#To display value of d:
print(d)

#to know the data type of d:
print(type(d))

d1 = 1 + 2j

#To display value of d1:
print(d1)

#to know the data type of d:
print(type(d1))

e = True

#To display value of e:
print(e)

#To display value of e:
print(type(e))

Out put of the above program is:

Hello Python
<class ‘str’>
52
<class ‘int’>
20.5
<class ‘float’>
(2+1j)
<class ‘complex’>
(1+2j)
<class ‘complex’>
True
<class ‘bool’>

About santosh G

Hi, i am Santosh Gadagamma, a tutor in Software Engineering and an enthusiast for sharing knowledge in Computer Science and other domains. I developed this site to share knowledge to all the aspirants of technologies like, Java, C/C++, DBMS/RDBMS, Bootstrap, Big Data, Javascript, Android, Spring, Hibernate, Struts and all levels of software project design, development, deployment, and maintenance. As a programmer I believe that, “The world now needs computers to function.” Hope, this site guides you as a learning tool towards greater heights. I believe that Education has no end points and i wish to learn more in the process of teaching you….,

Check Also

IDLE in Python (Integrated Development & Learning Environment)

While installing, python is come up with IDLE (GUI). That means it is GUI for …