Sitemap
Harshini M

Harshini M

DATA TYPES IN PYTHON

--

Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.

Following are the standard or built-in data type of Python:

Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.

Numeric Data Type:-

In Python, a numeric data type represents the data that has a numeric value. The numeric value can be an integer, floating number, or even complex number. These values are defined as int, float, and complex classes in Python.

EXAMPLE:

a = 2

print(a, “is of type”, type(a))

Output: 2 is of type

String Data Type:

A string is a collection of one or more characters put in a single quote, double-quote, or triple quote. It is represented by an str class.

Example:-

string1= “hello everyone”

print(string1)

output: hello everyone

List data type:

Lists are used to store multiple items in a single variable.

Get Harshini M’s stories in your inbox

Join Medium for free to get updates from this writer.

List items are ordered, changeable, and allow duplicate values.

List items are indexed, the first item has index [0], the second item has index [1], etc.

example:

l1=[1,2,3,4]

l2=[a,b,c,d]

print(l1+l2)

output:

[1,2,3,4, a, b,c,d]

Tuple Data Type:-

A tuple is defined as an ordered collection of Python objects. The only difference between tuple and list is that tuples are immutable i.e. tuples can’t be modified after it’s created. It is represented by tuple class. we can represent tuples using parentheses ( )

example:

t1=(1,2,3,4)

t2=(‘a’,’b’,’c’,’d’)

print(t1+t2)

output:

(1, 2, 3, 4, ‘a’, ‘b’, ‘c’, ‘d’)

Dictionary:

The dictionary is an unordered collection that contains key:value pairs separated by commas inside curly brackets. Dictionaries are optimized to retrieve values when the key is known.

The following declares a dictionary object.

Example:

capitals = {“USA”:”Washington D.C.”, “France”:”Paris”, “India”:”New Delhi”}

SET:

A set is a collection which is unordered, In Python sets are written with curly brackets. Duplicate values will be ignored.

--

--