Basic Data Type in Python
| Data Type | Literal | Example |
|---|---|---|
| Integer | 10 | x=10 |
| Float | 56.8 | y=56.8 |
| Complex | 5 8j | a=5 8j |
| String | "Jiocoding" | s="jiocoding" |
| Boolean | True/False | x=True |
Integer Data Type in Python
Integers Data Type: Any literal that includes only numeric characters (0 to 9) creates an object of type int. An object declared in this way can be referenced by a variable using the assignment operator.
Example of Integer Data Type in Python
y=300 print("Integer Data Type:",(x+y)) ============OUTPUT============ Integer Data Type:400 <class 'int'> |
Floating Data Type in Python
Floating Dats Type: A floating-point number consists of an integer part anda fractional part. In a program, these two parts are separated by a decimal point ().
Example of Float Data Type in Python
y=34.8 print("Float Data Type:",x+y) ============OUTPUT============ Float Data Type:45.3 |
Complex Data Type in Python
Complex numbers: A complex number consists of a real part and an imaginary part. They are useful for a variety
of scientific and engineering calculations, such as signal processing, quantum mechanics, and many other areas. A complex number in Python can be created using (5+6j).
Example of Complex Data Type in Python
y=3j print("Complex Data Type:",x+y) ============OUTPUT============ Complex Data Type:(5+3j) |
Boolean Data Type in Python
Boolean values: Python also has a built-in Boolean data type called bool. A variable of type bool has two possible values: True and False, which are the integers1 and 0, respectively.
Example of Boolean Data Type in Python
print("Boolean Data Type:",x) ============OUTPUT============ Boolean Data Type: True |
String Data Type in Python
Strings: A string in python is a sequence of one or more Unicode characters enclosed in single, double, or triple quotes. Python strings are immutable.
This means that when you perform an operation on strings you always create a new string object of the same type rather than modifying an existing string.
Example of String Data Type in Python
print("String Data Type:",name) ============OUTPUT============ String Data Type: Welcome To Jiocoding |
None Data Type in Python
None type: The None type in Python is a special object used to represent the absence of a value or empty. This type is used to indicate that a variable has no value or that a function returns nothing.
Example of None Data Type in Python
print("None Data Type:",x) printf(type(x)) ============OUTPUT============ Welcome To Jiocoding Website <class 'NoneType'> |
Advance Data Type in Python
| Data Type | Example |
|---|---|
| List | data=[1,"Jiocoding"] |
| Tuple | data=(1,"Jiocoding") |
| Dictionary | data={"website","jiocoding"} |
| Set | s={1,"jiocoding"} |
List Data Type in Python
List Data Type: List data type is a collection of data of different of data type. It can be used to store list of values. A list is created by using comma separated values between square brackets [].
List Data Type Python Example
print("List Data Type:",list_data) print(type(list_data)) ============OUTPUT============ List Data Type: ['Python', 'Java', 'C++', 'Jiocoding'] <class 'list'> |
Tuple Data Type in Python
Tuple Data Type: Tuple data type is a collection of data of different data types. We can not change the value of tuples. It is used to store tuple of values. A tuple has been created using parentheses (). Tuple data type is immutable.
Example of Tuple Data Type in Python
print("Tuple Data Type:",tuple_data) print(type(list_data)) ============OUTPUT============ Tuple Data Type: ('Python', 'Java', 'C++', 'Jiocoding') <class 'tuple'> |
Dictionary Data Type in Python
Dictionary Data Type: A dictionary Data type is an unordered collection of data of different data types. Dictionary value can be changed. A dictionary is created using curly brackets {}. Dictionary value can be stored in key value pairs.
Example of Dictionary Data Type in Python
print("Dictionary Data Type:",dic_data) print(type(dic_data)) ============OUTPUT============ Dictionary Data Type: {'name': 'Jiocoding', 'age': 30, 'city': 'Noida'} <class 'dict'> |
Set Data Type in Python
Set Data Type: A set Data type is a unordered collection of data of different data types. Set does not contain duplicate data. A Set value can not be fix index value. A set is created using curly brackets {}.
Example of Set Data Type in Python
set_data={100,200,300,400,500,600} print("Set Data Type:",set_data) print(type(se_data)) ============OUTPUT============ Set Data Type: {400, 100, 500, 200, 600, 300} <class 'set'> |

0 Comments