Python Data Types
Python data types refer to the kind of values that a variable may contain. Python has multiple built-in data types, some of which are:
Numeric Types
- int: 4, -6, 0
- float: 3.14, 2.0.
- complex 5 + 3i
Text Type
- str: “Hello Python”
Boolean Type
- Boolean data consists of True and False values.
Sequence Types
list:A list is a sequenced set of data elements comma-separated and surrounded by square brackets.
Example:
list1 =
["Orange",
"Mango",
"Apple"]
print(list1)
Output
['Orange', 'Mango', 'Apple']
tuple:A tuple is an ordered set of data items delimiting with a comma and within parentheses.
Example:
tuple1 =
(IBM",
"Google",
"Facebook")
print(tuple1)
Output
('IBM', 'Google', 'Facebook')
Mapping Type
dict:A dictionary is an unsorted collection of information with a key-value pair.
Example:
dict1 =
{"name":"Rahul", "age":22}
print(dict1)
Output
{'name': 'Rahul', 'age': 22}
Set Type
A set is an unordered collection of distinct items. The members of sets are enclosed in curly braces and separated by commas.
Example:
set1 =
{4, 8, 12, 5.2}
print(set1)
Output
{4, 8, 12, 5.2}