Data types in Python :
1.None
2.Numeric
3sequence
4.Dictionary
1.None_:
When User declare a variable and don't assigned a value to it , default data type of that variable is None (Same as Null in Java , C++,C )
2.Numeric:
sub types : (1) int :Positive or Negative whole number (Without a Fractional Part)
(2) flot:A real Number With Floating point representation
(3)Complex: In the form of (a+bj)
//imaginary part is shown by 'j' in Python
(4)Boolean : Data type with only two values either True or False
Note " T " and " F " are capital or Python throw error for true or false
Conversions Of Data types:
To convert one Data type into another ,there is special syntax in python
e.g.=
a=5.5
b=int(a)
print(b)
the value of b is print as 5 only as it is int data type
a=20
b=30
k=complex(a,b)
output=20+30j //Complex number
And in this way user can convert one data type into another data type
3. Sequence data type :
So Discussing on Data Types , A new learner should be aware about a concepts like list, Tuple sets,
list , Tuple, , String, Range , comes under sequence data type
a. List in Python :
List is ordered and changeable ,i.e. mutable it means we can change the content without changing there identity
list is define in a square brackets "[ ]"
e.g.: lis = ["Python", "C" ,"C++","Java"]
and to print elements in it
lis =[0] ==Python //output
There are some inbuild function that we can use "."after name of the list
b. Tuple in Python :
Tuple is almost same as a list ,The only difference in List and tuple is that Tuple is Immutable ,
to create a tuple we have to use round brackets "()"
e.g. : tup = (12,21,45,66,37)
there are some inbuild functions like count and index
count will provide number of occurrence of particular element in tuple
where index provides the index number
c. sets in python:
Do define a set in python ,we have to used the "{ }" curly Brackets .
In set there is no proper sequence of elements and here we can add and remove the elements
e.g. :
set1 = {"Python", "Java","C" }
print(set1)
//Output _ {'Java','C','Python'}
4. Dictionary in python:
This is one of the most Important concept in Python
In dictionary as well ,we have to use "{ }" Curly Brackets and we have to define two things i.e. (1) Key (2)Value
data={1:"One plus", 2:"Apple",3:"REal me",4:" Red me "}
we can access this Information i.e. Value By Just passing The Key
e.g. - data[1] // Output _"One plus"
or data.get(2) //output _"Apple"
The Dictionary is useful in sorting and finding the data , for example to find the information of student in college we just have to pass the roll no i.e. the key
We can merge two list into a dictionary
keys = [1,2,3]
Values =['A','B','C']
data =dict(zip(keys,Values)) // Syntax
//Output -{1:'A',2:'B',3:'C'}
The key should not be repeated
1.data types is immutable in python ?
- Data types in Python or in any programing language are mutable as well as immutableNow question arises that what is mutable and immutable data types
1.mutable data types are the data types where we can insert as well as delete the elements we can alter the elements .
e.g. mutable data types in Python : list ,Dictionary ,Sets and class(user define )
2.immutable data types are the data types where user can not alter the elements, Not able to insert new elements as well as not to delete the elements .
e. g . immutable data types in python :String, tuple , int ,float .
Important note:
char data type in Python:
Unfortunately there is No data type like char in python ,but we can define a string which will used as a char .
Important note:
char data type in Python:
Unfortunately there is No data type like char in python ,but we can define a string which will used as a char .