Data types

Python Programming language Data types

Python programming language Datatypes

In this tutorial, we discuss the concept of Python programming language data types.

The data type is an important concept in every language including python language. Python language has a variety of data types to manipulate the python program. The value of every python language is has a data type.

In this topic, we can see some of the important data types in Python that are listed below.

 

Python programming numbers

Python numbers as a data type are denoted by integers,  floating point numbers and complex numbers in Python language.

The above three dtat types are defined as int, float and complex respectively

Example

age=20          //this is a variable age holds value 20 as integer type
average=56.7    //this is a variable average holds value 56.7 as float data type
num=1+2j        //this is a variable num holds value 1+2j as complex data type

Program

a=5    #integer number
print("a is",a)

b=4.55    #floating point number
print("b is",b)

c=1+2j   #floating point number
print("c is",c)

When the above code is executed, it produces the following results

a is 5
b is 4.55
c is (1+2j)

 

 

Python programming String

The string is a sequence character In Python, we can use single quotes, double quotes or triple quotes for string representation.

Multi-line string can be denoted between triple quotes(”’, “””)

Example

str1='This is a string' // single quotes represant a Strng

str2="This is another string" //double quotes represent a String

str3="""This is multi

line string"""//triple quotes represent a multi line String

 

Program

str1='Hollow i am Python'


print("str1[4]=",str1[4])
#display str1[4]

print("str1[1:6]=",str1[0:6])
#display str1[1:6]

print("str1[12:18]=",str1[12:18])
#display str1[12:18]

When the above code is executed, it produces the following results

str1[4]= o
str1[1:6]= Hollow
str1[12:18]=Python

 

Python programming list

This list is very easy to manipulate and a mostly used data type in python and it has an ordered sequential values in a single name.

All the items in a list may be the same type of variable but no need to be the same type.
It can have mixed data types

Example for list

marks=[45,67,87,65,48,98]; //list contains same data types

a=[34,54,56.7,”text”]//list contains different data type

Program

number=[2,4,6,8,10,12,14,16,18,20]

print("number[2]=",number[2])
#display number[2]

print("number[0:3]=",number[0:3])
#display number[0:3]

print("number[7:]=",number[7:])
#display number[7:]

When the above code is executed, it produces the following results

number[2]= 6
number[0:3]= [2, 4, 6]
number[7:]= [16, 18, 20]

 

Python programming tuple

A tuple is an ordered sequenced data type looks like a list, but both have some differences. Tuple has data between parenthesis and every data is separated by the symbol of “comma (,)”. A tuple can have a mix data type and its content can not be changed (immutable data type)

Example

Tuple1=()  #empty tuple

Tuple1=(345)  #Tuple can have single data type

Tuple3=("Blue", 555, 45.34, "Kamal", "Orange")  #Tuple contains different data types

colour=("Blue", "Red", "Black", "White", "Orange")  #Tuple contains same data types

 

Program

tuple=(23,"Python",4.3,1+2j)
#display tuple[2]
print "tuple[2]=",tuple[2]

#display tuple[3]
print "tuple[3]=",tuple[3]

#display tuple[0:3]
print "tuple[0:3]=",tuple[0:3]

When the above code is executed, it produces the following results

tuple[2]= 4.3
tuple[3]= (1+2j)
tuple[0:3]= (23, 'Python', 4.3)

 

Python Language set

Python set is an irregular collection of unique items. Sets have data between braces(curly brackets) and every data is separated by the symbol of “comma “;

 

Example

fruits={"Mango","Apple","Pine apple","Orange"}

age={54,27,18,62,54,76,31}

 

Program

fruits={"Mango","Apple","Pine apple","Orange"}
print(fruits)

When the above code is executed, it produces the following results

['Pine apple', 'Orange', 'Mango', 'Apple']

 

 

Python language dictionary

Python dictionary is an unordered collection of value with key-value pairs. Dictionaries are defined between curly brackets( braces) with each element of a pair of key-value.

When we use a huge amount of data we can use dictionary data type. when we know the key(pair of data) we can retrieve particular data or value

Dictionary form  key: value

Example

Dict={1:name, 2:age, 3:male}

 

Program

Dict={1:34,2:56.5,3:'kumar'}

#display dictionary variable

print("Dict=",Dict)#display element Dictionary
print("Dict[2]=",Dict[2])#display element Dict[2]

When the above code is executed, it produces the following results

Dict= {1: 34, 2: 56.5, 3: 'kumar'}
Dict[2]=56.5

 

Similar post

Data type in Java

Data type in C language

Data type in C++ language

 

Write a Python program to print an integer
Pointer in c++ programming language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

1 month ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago