Python Data Types
Data types in Python
In Python, variables can hold the values of different types that are called data types. Python Data Types are used to define the operations and store each of them.
Built-in Data Types in Python
There are five types of Python Data Types exist:
1. Numbers: Numbers refer to a numeric value. In Python, there are four types of numbers are exist.
- integer
- long integer
- floating point
- complex number
2. String: String is a group of characters. In Python, you can use a string in the following ways:
- single quotes string: This string can be written as ‘Python’ .
- double quotes string: This string can be written as “Python” .
- triple quotes string: triple quotes string can be written as ”’Python”’ .
3. List: Lists consist of items separated by commas and enclosed within square brackets([]). It is the most versatile data type in Python Programming Language.
Example:
list=['a','hello',25,3.14] print(list)
Output :
[‘a’,’hello’,25,3.14]
4. Tuple: A tuple also consists of several values separated by commas and enclosed within parenthesis. But you can’t change the values in a tuple. So, a tuple is called a read-only data type.
Example:
Tup=('a','hello',25,3.14) print(Tup)
Output :
(‘a’,’hello’,25,3.14)
5. Dictionary: In Python, Dictionary is used to store the data in key-value pairs. The key values are strings and the value can be of any data type. The key-value pairs are enclosed with curly braces({}) and each key-value pair is separated from the other using a colon (:).
Example:
Dict={"Student_Name":"Rohit","Roll_No":555) print(Dict["Student_Name"]) print(Dict["Roll_No"])
Output:
Rohit
555