Python Data Types

Python Simple DataTypes:

A datatype represents the type of data stored into a variable or memory in Python also.




Basically, Python has inbuilt datatypes – Already available in python.

And User-defined datatypes – Datatypes created by programmers.

I). Built-in datatypes:

*None Type

*Numeric Types    – int, float, complex

*Sequences         – str, bytes, list, tuple, etc.

*Sets                       – set, frozenset

*Mapping             – dict

None :

‘None’ datatype represents an object that does not contain any value.

In Java – NULL

In Python – None

Numeric datatypes:

1.int:

It represents an integer number

It is number without the decimal part and fraction part.

Example:

 >>> x=100

>>>type(x)

<class 'int'>

2.float:

Float represents a floating number

A floating number contains decimal part

Example: 

>>>x=100.25

>>>type(x)

<class 'float>

3.Complex Data type:

The complex number is number that is written in the form of a+bJ or a+bj

a: real part

b: imaginary part

Example: 

>>>a=1+3j

>>>b=5+7j

>>>c=a+b

>>>print(c)

(4+10j)

Bool data  type:

The bool data type in Python represents boolean values.

>>>a=20

>>>b=10

>>>print(a>b)

True

Sequences in Python:

A sequence represents a group of elements or items.

Mainly 6 types of sequences in Python:

1.str

2.bytes

3.bytearray

4.list

5.tuple

6.range

Sets:

A set is an unordered collection of elements that is a set. Set does not accept duplicate elements.

Here two types of sets

1.Set datatype:

Set elements should be separated with a comma(,)

Set always print only unique elements.

Example :

>>>a={100,200,300,400,500,100,100}

>>>print(a)

{100,200,300,400,500}

2.frozenset datatype:

Frozenset datatype is a create frozenset bypassing set data

Cannot be modified(update and remove methods will not work)

Example:

>>>x={500,600,700,800}

>>>y=frozenset(x)

>>>type(y)

<class 'frozenset'>
>>>print(y)
frozenset({500,600,700,800})

Mapping Type:

A map represents a group of elements in the form of key-value pairs so that when a key is given will retrieve a value

The dict datatype is an example of a map. Dict represents a dictionary that contains a pair of elements first one is Key and second one is Value.

Example:

>>>d={10:"Vijay",20:"Murali"}

>>>print(d)

>>>d[10]

"Vijay"

>>>type(d)

<class 'dict'>




Leave a Reply

Your email address will not be published. Required fields are marked *