Python Tokens
Python Tokens :
1. Keyword
2. Identifiers
3. Literals
4.operators
1. Keyword :
• python keywords are special reserved. words
• special meaning to the compiler
• each keyword have special meaning
• never use it as variable
variable : data name
Is symbolic name that is reference an object
Keyword :
False await else import pass
None break except in raise
True class finally is return
and continue for lambda try
as def from nonlocal while
assert del global not with
async elif if or yield
2. Identifiers :
Identifiers are the name used to identify a variable, function, class or object
Rules :
1. Keyword should not be used as identifier name
2. Python is case sensitive ( a, A both are different)
3. First character of identifier can be character and underscore (_) but not digit
3. Literals in python :
# String literal
# Numeric literal
# Boolean literals
# Special literal
# string literal : any things which return in single and double quote treated as string
Name = "kanchan"
Name1 = 'kanchan1'
Multiline string : 3 single quote use
''' hello students how are you
I hope all are good
Your exam starts on monday '''
# Numeric Literal : int , long, float, complex
Int : + , - ex: 10, -7
Long : unlimited int size ex: 152673662
Float : decimal point ex: 5782.79
Complex: a+bj
# Boolean Literal: can have only 2. values
•True •False
# special literal :
• only 1 special literal: None
•Used to specify to the field that is not created
Val = 10
Val1 = None
4. Operators :
Arithmetic operator : (+ ,- ,* ,/ ,%)
Used to perform arithmetic. operations take 2 operand
a2 , b2 = 10 , 10
c1=a2 + b2
c2 = a2*b2
c3 = a2/b2
c4 = a2-b2
print (c1,c2,c3,c4)
Assignment operators :(= ,+= ,-= ,*=)
Used to assign value to a variable
var = 10
var = 10
var += 9 # var = var + 10
val = 10
val *= 9
str = 15
str -= 10
print (var,val,str)
comparison operators :(> ,< ,>= ,<=,!= ) used to compare 2 values and return true or false as output
a = 10
b = 20
val1 = a < b
var3 = a > b
str1 = a <= b
val2 = a >= b
var2 = a != b
print(val1,var3,str1,val2,var2)
Logical operators :( and, or, not)
Used to perform logical. calculations and return true or false as output
c9= a < b and a > b
c10 = a < b or a > b
print ( c9,c10)
bitwise operators : (<< ,>> ,& ,! ,~)
Used to perform bitwise calculations
A = 7 | 5
B = 7 & 5
#C = 7 ~ 5
D = 7 >> 5
E = 7<< 5
print(A,B,D,E)
identity operators : ( is, is not)
Test if the two operands share an identity
A1 = 6
B1 = 8
A2 =A1 is 6
B2 = B1 is not 8
C= B1 is 8
NAME = "KANCHAN"
x = NAME is "KANCHAN"
print(A2,B2,C,x)
Membership operators : ( in, not in)
Test whether a value is a member of a sequence
name = ['kanchan','koyal','monali']
X = 'kanchan' in name
X1 = 'yal' in name
x1 = 'yal' in 'koyal'
x2 = "koyal" not in name
print(X,X1,x1,x2)
Comments
Post a Comment
If you have any doubts, please let me know