regularpython@gmail.com
Python Data Types
Data types are used to store data or information in a variable. Python data types are dynamic because we don’t need to mention type of the variable. But in other languages, we should mention the type of data. See the below example you can get the clarity.
Example:
In java:
Short Age = 24
In python:
Age = 24
Data types in python,
- Numbers
- Strings
- Lists
- Tuples
- Dictionaries
- Sets
- Booleans
Numbers:
Number data types are used to store integers or numbers or float values of imaginary values.
Example:
x = 10 (Integer)
x = 10.5 (float)
x = 10+i5 (imaginary)
Strings:
String is nothing but a group of characters. String data types are used to store strings in a variable.
Examples:
X = ‘regularpython.com’
X = “regularpython.com”
X = “““regularpython.com”””
Lists:
Lists are used to store a sequential data types
Example:
X = [1, 2, 3, 4, 5, 6]
X = [‘mangoes’, ‘orange’, ‘gapes’]
X = [1,2,3, ‘mangoes’, ‘oranges’]
Tuples:
Tuples also used to store sequential data types. But the difference between tuple and list is,
List is mutable (we can edit, update, delete) and tuple is immutable (we can’t edit, update, delete).
Example:
X = (1, 2, 3, 4, 5, 6)
X = (‘mangoes’, ‘orange’, ‘gapes’)
X = (1,2,3, ‘mangoes’, ‘oranges’)
Dictionaries:
Dictionaries are used to store data in the form of a key-value pair. Dictionary is nothing but a JSON data type. In python, we called a dictionary, in other languages we called it JSON.
Example:
X = { ‘name’:’ python’, ‘Rank’: 1}
Sets:
Sets are mainly used to get or store unique values only. If you want to remove duplicates then you can use sets.
Example:
X = {1,2,3,4}
Boolean:
Boolean data types are mainly in conditions. Boolean data types,
Ø True
Ø False
Example:
if 2==2:
print(‘same’)
else:
print(‘Not Same’)