Computer science
Python tour
TOKEN in PYTHON =
The smallest individual unit in a program is known as a Token or a lexical unit.
> Python has following tokens:
(i) KEYWORDS (II)Identifiers(Name) (iii) Literals
(iv) Operators (v)Punctuators
# a sample python program#
for a1 in range(1,10):
if a%5==0: punctuators
Keyword
print(a1) Literals
operators
identifiers
KEYWORDS.
Keyword are the predefined words with special meaning to the language compiler or interpreter.
False assert del for in or while
None break elif from is pass with
True class else global lambda raise yield
And continue except if nonlocal return
As def finally import not try
Computer science
Python tour
Identifier :-
=> Identifiers are the names given to different parts of the program
Example:- variable, object, classes, functions, lists, NOTE
Python is case sensitive as it treats upper
And lower-case character differently
=>Rules for create python identifiers:
❑ variable names must only be non-keywords with no spaces in between.
❑ Variable names must be made up of only letters, number, and underscore(_)
❑ Variable names cannot begin with a number , although they can contain number
Valid identifier = MYFILE myfile _chk z2toxk shatrughan8585 rahees8377 ack8802
Invaild identifier = DATA-REC 26hello break My.file ?humsahr
Computer science
Python tour
Literals / Values
Literals are data items that have fixed/constant values
(i)string literals (ii)Numeric literals (iii) boolen literlas
(iv) Special Literal None
Operators
-- Operators are tokens that some computation / action when applied to variable and other objects in an
expression.
Operators sign
Arithmetics operators (+,-,*,/,%,**,//)
Bitwise operators (&,^,l)
shift operators (<<,>>)
Identity operators (is, is not)
Computer science
Python tour
operators sign
Relational <,>,>=,>=,==,!=
Logical and ,or
Assignment =
Membership in , not in
Arithmetic-assignment /=,+=,-=,*/,%=,**=,//=
Computer science
Python tour
Punctuators :-
= > Punctuators are symbols that are used in a programming language to organize sentence structures
and indicate the rhythm and emphasis of expressions, statements, and program structure.
Example:
‘ “ # \ ( ) {} [ ] @ , : ` . =
print(punctuators)
while true :
a={1:kartik,2:undercover}
S=( 7,8,9,self)
Computer science
Python tour
Variables
Variable represents labelled stroge location, whose values can be manipulated during program run.
=> Variable create
To create a variable,just assign to its name the value of appropriate type.
Example :
student = “ Shatrughan”
Age= 12
# here “student “ is a variable name “Shatrughan” is the value of variable and “” quote is represent
the data type of variable #