Data Types In Python
Python Data types
Data types is the value which we want to store in variables .In which variable are store in different data types Python provide the type() function to Identify the type of variable .In Python there are some standard data types which are used to define storage method .In Python there is no need to define the type of variable in the statement of variable declaration .when the value is assigned to the variable , the interpreter set the data type of variable.
There are five types of data types provide by Python
1. Number
2. String
3. List
4. Tuple
5. Dictionary
Number :
Number are used to store numeric value .Number object is generated by Python when a number assigned to a variable.
In Python there are four types of numeric data.
integer (int) : signed integer such as 5,10,15,etc.
long : used for high range value like 1234567890
Float : used for point number such as 1.21,3.14,etc.
complex : used for complex number such as 1.21j, 2.14+3.14j,etc.Complex number contain ordered pair x+jy where x and y are real and imaginary number resp.
String (str): string is the sequence of character represented in the quotation mark .Python allow us to use single , double and triple quotes for the defining a string.+ Operator is use to add two strings.
Eg.
str1="My"
str2=" name is "
print(str1+str2)
OP : My name is
[Program finished]
List : List is a collection of Python object like string , integer .
It is represented by the square bracket " [ ] " and separated by the comma (,) .
Eg .
A = [10,20,30,40,50]
print(A)
OP :
[10, 20, 30, 40, 50]
[Program finished]
Tuples : In Python a Tuple is considered as a sequence of immutable objects. Tuple are similar as list we use ' ( ) ' instead of ' [ ] ' . We cannot modify the tuple .
Eg.
tup1 = (10,20,30,40,50)
print(tup1)
print(tup1[3])
OP :
(10, 20, 30, 40, 50)
40
[Program finished]
Dictionary : In the Dictionary collected data represented in key-value format .Curly braces { } are used to enclosed the collection of key-value pair. Key and value are separated by the colon (:) .
Eg.
A = {10:"Ten" , 20:"Twenty" , 30:"Thirty"}
print(A)
OP :
{10: 'Ten', 20: 'Twenty', 30: 'Thirty'}
[Program finished]
Conclusion : Here we see the data types in Python .
👌👌
ReplyDeleteReally useful bro!!!!!!😉🤞
ReplyDelete