Learn Python – Python Data Types- Basic and advance

Variables can maintain values, and each and every value has a data-type. Python is a dynamically typed language; therefore we do no longer need to define the type of the variable whilst declaring it. The interpreter implicitly binds the value with its type.

a = 5  

The variable a holds integer fee five and we did not define its type. Python interpreter will mechanically interpret variables a as an integer type.

Python allows us to take a look at the kind of the variable used in the program. Python offers us the type() function, which returns the type of the variable passed.

Consider the following example to define the values of exceptional records types and checking its type.

b="Hi Python"  
c = 10.5  


<type 'int'>
<type 'str'>
<type 'float'>

Standard data types

A variable can keep different sorts of values. For example, a person’s identify ought to be saved as a string whereas its identification should be saved as an integer.

Python presents a variety of widespread information kinds that define the storage approach on each of them. The records types described in Python are given below.

Sequence Type

In this area of the tutorial, we will provide a brief introduction of the above data-types. We will talk about every one of them in detail later in this tutorial.


Number shops numeric values. The integer, float, and complicated values belong to a Python Numbers data-type. Python provides the type() function to know the data-type of the variable. Similarly, the isinstance() feature is used to take a look at an object belongs to a precise class.

Python creates Number objects when a wide variety is assigned to a variable. For example;

a = 5  
print("The type of a", type(a))  
b = 40.5  
print("The type of b", type(b))  
c = 1+3j  
print("The type of c", type(c))  
print(" c is a complex number", isinstance(1+3j,complex))  


The type of a <class 'int'>
The type of b <class 'float'>
The type of c <class 'complex'>
c is complex number: True

Python supports three types of numeric data.

Int - Integer value can be any length such as integers 10, 2, 29, -20, -150 etc. Python has no restriction on the length of an integer. Its value belongs to int
Float - Float is used to store floating-point numbers like 1.9, 9.902, 15.2, etc. It is accurate upto 15 decimal points.
complex - A complex number contains an ordered pair, i.e., x + iy where x and y denote the real and imaginary parts, respectively. The complex numbers like 2.14j, 2.0 + 2.3j, etc.

Sequence Type


The string can be defined as the sequence of characters represented in the quotation marks. In Python, we can use single, double, or triple costs to outline a string.

String dealing with in Python is a straightforward project because Python provides built-in functions and operators to perform operations in the string.

In the case of string handling, the operator + is used to concatenate two strings as the operation “hello”+” python” returns “hello python”.

The operator * is recognised as a repetition operator as the operation “Python” *2 returns ‘Python Python’.

The following example illustrates the string in Python.

Example – 1

str = "string using double quotes"  
s = '''''A multiline 


string using double quotes
A multiline

Consider the following instance of string handling.

Example – 2

str1 = 'hello javatpoint' #string str1    
str2 = ' how are you' #string str2    
print (str1[0:2]) #printing first two character using slice operator    
print (str1[4]) #printing 4th character of the string    
print (str1*2) #printing the string twice    
print (str1 + str2) #printing the concatenation of str1 and str2    


hello javatpointhello javatpoint
hello javatpoint how are you


Python Lists are comparable to arrays in C. However, the listing can contain information of exclusive types. The gadgets stored in the listing are separated with a comma (,) and enclosed within square brackets [].

We can use slice [:] operators to get entry to the statistics of the list. The concatenation operator (+) and repetition operator (*) works with the listing in the equal way as they were working with the strings.

Consider the following example.

list1  = [1, "hi", "Python", 2]    
#Checking type of given list  
#Printing the list1  
print (list1)  
# List slicing  
print (list1[3:])  
# List slicing  
print (list1[0:2])   
# List Concatenation using + operator  
print (list1 + list1)  
# List repetation using * operator  
print (list1 * 3)  


[1, 'hi', 'Python', 2]
[1, 'hi']
[1, 'hi', 'Python', 2, 1, 'hi', 'Python', 2]
[1, 'hi', 'Python', 2, 1, 'hi', 'Python', 2, 1, 'hi', 'Python', 2]


A tuple is comparable to the listing in many ways. Like lists, tuples also contain the series of the objects of exclusive records types. The objects of the tuple are separated with a comma (,) and enclosed in parentheses ().

A tuple is a read-only information structure as we cannot adjust the dimension and value of the objects of a tuple.

Let’s see a simple example of the tuple.

tup  = ("hi", "Python", 2)    
# Checking type of tup  
print (type(tup))    
#Printing the tuple  
print (tup)  
# Tuple slicing  
print (tup[1:])    
print (tup[0:1])    
# Tuple concatenation using + operator  
print (tup + tup)    
# Tuple repatation using * operator  
print (tup * 3)     
# Adding value to tup. It will throw an error.  
t[2] = "hi"  


<class 'tuple'>
('hi', 'Python', 2)
('Python', 2)
('hi', 'Python', 2, 'hi', 'Python', 2)
('hi', 'Python', 2, 'hi', 'Python', 2, 'hi', 'Python', 2)

Traceback (most recent call last):
  File "main.py", line 14, in <module>
    t[2] = "hi";
TypeError: 'tuple' object does not support item assignment


Dictionary is an unordered set of a key-value pair of items. It is like an associative array or a hash table the place each key shops a specific value. Key can hold any primitive information type, whereas fee is an arbitrary Python object.

The items in the dictionary are separated with the comma (,) and enclosed in the curly braces {}.

Consider the following example.

d = {1:'Jimmy', 2:'Alex', 3:'john', 4:'mike'}     
# Printing dictionary  
print (d)  
# Accesing value using keys  
print("1st name is "+d[1])   
print("2nd name is "+ d[4])    
print (d.keys())    
print (d.values())    


1st name is Jimmy
2nd name is mike
{1: 'Jimmy', 2: 'Alex', 3: 'john', 4: 'mike'}
dict_keys([1, 2, 3, 4])
dict_values(['Jimmy', 'Alex', 'john', 'mike'])


Boolean kind provides two built-in values, True and False. These values are used to determine the given declaration authentic or false. It denotes by means of the type bool. True can be represented by means of any non-zero cost or ‘T’ whereas false can be represented through the zero or ‘F’. Consider the following example.

# Python program to check the boolean type  


<class 'bool'>
<class 'bool'>
NameError: name 'false' is not defined


Python Set is the unordered collection of the records type. It is iterable, mutable(can regulate after creation), and has unique elements. In set, the order of the factors is undefined; it may also return the changed sequence of the element. The set is created by way of the use of a built-in characteristic set(), or a sequence of factors is surpassed in the curly braces and separated by means of the comma. It can comprise a variety of kinds of values. Consider the following example.

# Creating Empty set  
set1 = set()  
set2 = {'James', 2, 3,'Python'}  
#Printing Set value  
# Adding element to the set  
#Removing element from the set  


{3, 'Python', 'James', 2}
{'Python', 'James', 3, 2, 10}
{'Python', 'James', 3, 10}