Python Data Types:
1.Fundamental DT's:
int,float,bool,complex,str
2.Collection DT's:
bytes,bytearray,list,tuple,range,set,frozenset,dict,None
4.tuple data type:
--------------------------
-->Values should be enclosed with parenthesis ( ) is an optional.
-->Insertion order is preserved.
-->Hetrogenious objects are allowed.
-->Duplicates are allowed.
-->Indexing and slicing are supported.
-->Growable nature is not applicable.
-->It is immutable.
5.range data type:
----------------------------
Range data type represents a sequence of numbers.
Ex:
range(10):generates 0 to 9
range(10,20):generates 10 to 19
range(10,50,5):generates 10,15,20,25,30,35,40,45
-->The elemnts present in the range data type are not modifiable. i.e range data
type is immutable.
6.set data type:
-----------------------
-->Values should be enclosed with curly braces { }.
-->Insertion order is not preserved.
-->Hetrogenious objects are allowed.
-->Duplicates are not allowed.
-->Indexing and slicing are not supported.
-->Growable in nature.
-->It is a mutable.
7.frozenset data type:
---------------------------------
-->It is exactly same as set except that it is immutable.
-->Hence we cant use add or remove functions.
s = {10,20,30}
fs = frozenset(s)
type(fs)
fs.add(40)#'frozenset' object has no attribute 'add'
fs.remove(10)# 'frozenset' object has no attribute 'remove'
8.dict data type:
-------------------------
-->If we want to represent a group of values as key-value pairs then we should go
for dict data type.
d = {k-v,k-v,k-v,....}
Ex:
d = {100:'sunny',200:'bunny',300:'vinny'}
type(d)#<class 'dict'>
d[100]#'sunny'
d[400]#KeyError: 400
-->Duplicate keys are not allwoed but values can be duplicated. If we are trying to
insert an entry with duplicate key then old value will be replaced with new value.
d[100] = 'pinny'
-->We can create an empty dictionary as:
d = {}
type(d)
d[key] = value
9.None data type
-------------------------
-->None means nothing or no value associated.
-->If the value is not available, then to handle such type of cases None
introduced.
-->It is something like null value in java.
a = None
type(a)#<class 'NoneType'>
Escape Characters:
In string literals we can use escape characters to associate special meaning
s = 'Naresh IT'
print(s)#Naresh IT
s = 'Naresh\nIT'
print(s)
Naresh
IT
s = 'Naresh\tIT'
print(s)#Naresh IT
Constants:
-----------------
-->Constant concept is not applicable in python.
-->But it is convention to use only upper case characters if dont want to change.
MAX_VALUE = 100
-->It is just convention but we can change the value.
1.Identifiers
2.Keywords/Reserved words
3.Data types
4.Escape chars
5.Constants