Data types in Python

Variables are used to stores values and every value stored in variables has data types. There are various data types in python. Some listed below.

Python Numbers:--

Integer, Decimal point numbers and comples numbers come in the category of python numbers. Example-

>>> a = 67
>>> print(a, ' Type of this is ', type(a))
67  Type of this is  <class 'int'>
>>> b = 5.8
>>> print(b, ' Type of this is ', type(b))
5.8  Type of this is  <class 'float'>
>>> c = 6 + 2j
>>> print(c, ' Type of this is ', type(c))
(6+2j)  Type of this is  <class 'complex'>

Python List:--

A list is a collection which is ordered and changeable. In Python lists are written with square brackets. All the items in List can be of different data types.

Python Tuple:--

A tuple in Python is similar to a list. The difference between the two is that we cannot change the elements of a tuple once it is assigned whereas we can change the elements of a list. Means Tuples are immutable while Lists are mutable.

Python String:--

String in python is a sequence of Unicode characters. We can use single quotes or double quotes to represent strings.

Python Sets:--

A set in python is a collection of unordered items. In Python sets are written with curly brackets.

Python Dictionary:--

Dictionary in python is a collection of key value pairs.

Total Views: 362