0% found this document useful (0 votes)
11 views16 pages

Tokens

Notes for token
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views16 pages

Tokens

Notes for token
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Tokens in Python

► The smallest unit/element in the python


program/script is known as a Token or a Lexical
unit.
► Python has following Tokens:
► Keywords
► Identifiers
► Literals
► Operators
► Punctuators
Keywords
Keywords are the reserve words/pre-defined words/special words
of python which have a special meaning for the interpreter.
False True None def if

lambda class yield continue else


assert or while break elif

del from is not pass

for global finally import as

in nonlocal return With And


int except Raise print
Identifiers(user defined names)
► Identifiers are the name given to the different
programming elements like variables, objects,
classes, functions, lists, dictionaries etc.

Non- • Must be • Cannot


keyword made up of begin
word only letters, with a
with no numbers Number,

Rule 3
Rule 2
Rule 1

space in and although


between Underscore(_) may
contain
numbers
\

Identifiers
Some Valid Identifiers:
Literals
► Literals are the data items that have a fixed or
constant value
String Literals
► A string literal is a sequence of characters surrounded
by Quotes (Single, Double or Triple Quotes).

Single Line Strings MultiLine Strings


• Must • Spread
terminate across
in one line multiple
lines
String Literals

Single line String


>>>Txt1 = “Hello World”

Multiline string
>>>Txt2 = “Hello\
World”
>>>Txt3 =‘’’Hello World”’
Numeric Literals
► Numeric Literals are numeric values like integer
floating point number or a complex number

float complex

• complex
number
literals
Numeric Literals
► integer literals

Decimal Octal Form Hexadecimal


Form form

• Digits 0-9 • Begin with Oo • Begin with Ox


• Base 10 • Base 8(0-7) • Base 16(0-9,a-f)
• e.g. 1234 • e.g. 0o32 • e.g.OxAF
Numeric Literals
► Floating Point Literals/ Real Literals & Complex Numbers
n

Floating point Complex Number

• Decimal point • a+bj form


divides the • a & b are real
integer and fraction • j = v-1, imaginary
part • e.g. 2+3j
• e.g. -13.0, 3.E2,
0.17E5
Boolean Literals
► A Boolean literal in Python is used to represen
one of the two Boolean Values i.e. True or False

Boolean Boolean
True False
Special Literal – None(empty legal value)

In python, None literal is used to indicate


absence of value
Identifiers
Some Invalid Identifiers:

VID-REC
• Contains special character -(hyphen)

2020RNO
• Starting with a Digit

continue
• Reserved keyword

Emp.Code
• Contains special character . (dot)
Operators in Python
► Operators are the symbols or words that perform some kind
of operation on given values (operands) in an expression and
returns the result.
arithmetic • +,-,/,*,%,**,//
bitwise • &, ^, |

identity • is, is not


relational •>,<,>=,<=,==,!=

logical • and, or,not


shift • <<, >>
Assignment •=

Membership • in, not in


+=,-=,//=,**=,*=,/=
arithmetic-assignment
Punctuators in Python
► Punctuators are the symbols that are used in
programming language to organize sentence structure,
indicate the rhythm and emphasis of expressions,
statements and Program Structure.
► Common Punctuators are:

‘ ‘’ “” # \ (){}[] @,
, : .;
Tokens in Python
Keywords are the reserve words of python which have a special meaning for
the interpreter.

Identifiers are the name given to the different programming elements like
variables, objects, classes, functions, lists, dictionaries etc.

Literals are the data items that have a fixed /constant value.

Operators are the symbols or words that perform some kind of operation on
given values (operands) in an expression and returns the result.

Punctuators are the symbols that are used in programming language


to organize sentence structure, indicate the rhythm and emphasis of
expressions, statements and Program Structure.

You might also like