Professional Documents
Culture Documents
Day 3
Day 3
----------------------
Identifiers
-------------
A name in python program is called as identifer
It can be a variable name or class name or function name or method name
eg:
a=10 #-->a is a identifer/name
class Demo #--> class name Demo is a identifer
def func1 # func1 is a function name and it is a identifer
Note : apart from these combination if we are using any other things we will get
syntax error
eg;
sagar=10 #valid
$agar=10 #invalid
print($agar)
Note:
sachinTendulker =10 #--> camel case convention in JAVA
sachin_tendulker =10 #--> snake case convention in Python
eg;
abcdefghijklmnopqrstuvwxyz=10 #valid
print(abcdefghijklmnopqrstuvwxyz)
number_value=10 #valid
print(number_value)
* we can not use the reserved keywords as identifers
eg;
name='sagar' #valid
for = 10 #invalid
if =20 #invalid
def = 30 #invalid
class =90 #invalid
try =50 #invalid
task
------
1sachin10tendulker -->invalid
_abc_def -->valid
ca$h = 100 -->invalid
Integer = 10 -->valid
int= 10 -->valid
Note :
------
1. if identifer is starting with _ symbol then it indicates as private member
eg;
_name= 'sagar'
3.if identifer is starting with __ and ending with __ symbol then it indicates
magical methods
eg;
__init__
Reserved Keywords
-------------------
In python some words are reserved to represent some meaning or functionality
Such type of words are called as Reserved keywords
eg;
import keyword
keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break',
'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for',
'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or',
'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
Note:
-------
1. all the keywords are alphabets [lower case]
except
-->False None True
eg;
a= True
#a= TRUE #invalid
a= 'TRUE'
#a= true
a= 'true'
print(a)
eg;
#True =10 #invalid
TRUE =10 #valid
'TRUE' =10 #invalid
print('TRUE')
Data Types
-------------
Data type represents the type of the data
In python we are not required to specify the datatype explicitly like java
Based on the value provided to the variable datatype will be decided automativally
Hence python is called as "Dynamically typed language"
eg;
a=10 --> valid in python
int a=10 --> valid in java
#intermediate datatypes
------------------------
6.bytes
7. bytearray
8. range
Advanced datatypes
-------------------
9. list
10. tuple
11. set
12. frozenset
13. dict
extra
-------
14. None
a=10
print(type(a)) #<class 'int'>
#to check the datatype of the data we use type function
a=10
print(id(a))
#to check the memory address of the data or object
we will use id function
eg;
#Case-1
a=10
print(id(a))
print(a)
a=20
print(id(a))
print(a)
#Case-2
a=10
print(a)
print(id(a))
b=10
print(b)
print(id(b))
Fundamental datatypes;
-----------------------
1. int data type;
-------------------
eg;
a=10
print(a) #10
print(type(a)) # int
note : in python2 we have long datatype where as in python 3 we dont have long
datatype we just only int datatype.