python
• Who was developed Python???
• Python was developed by Guido Van Rossum
in early 1990s.
• Tokens in python:
• The smallest individual unit in a program is
known as Token or a lexical unit.
• Python has following tokens:
• 1. Keywords
• 2.identifiers(Names)
• 3.Literals
• 4.operators
• 5.punctuators
• 1.Keywords:
• A keyword is a word having special meaning
reserved by programming language.
• For eg: for,in,False,None,break,finally,try
• Identifiers(Names)
• Identifiers are the names given to different
parts of the program
viz.variables,objects,classes.lists,dictionaries.
• The naming rules for python identidiers can be
summarized as follows:
• Variable names must only be a non-keyword
word with no spaces in between.
• Variable names cannot begin with a
number,although they can contain numbers.
• (Python is case sensitive as it treats upper and
lower-case characters differently.
• Valid identifiers:
• Myfile
• MYFILE
• _CHK
• Z2T0Z9
• Break
• My.file
Literals/values
• Literals are data items that have a
fixed/constant value.
• Python allows several kinds of literals,which
are being given below.
• 1.String literal:
• A string literal is sequence of characters
surrounded by quotes(single or double or
triple quotes)
• Single line strings:
• Single line strings must terminate in one
line...the closing quotes shouls be on the same
line as that of the opening quotes.
• Multiline strings:
• Strings are strings spread across multiple
lines.with single and double quotes.each line
other that the concluding line has an end
character as \(backslash)but with triple
quotes,no blackslash is needed at the end of
intermediate lines.
• Text1=“Hello World”
• #Multi-line String
• Text2=“Hello\
• World”
• # Triple line string:(no backslash needed)
• Text3=‘ ‘ ‘ Hello
• world’ ‘ ‘
• Numeric Literals:
• Int(signed integers)-often called just integers
or ints,postive or negative whole numbers
with no decimal point.
• Decimal form:an integer beginning with digits
1-9 .for eg:1234,4100 etc
• Octal form:An integer beginning with 0o(Zero
followed by letter o)eg:0o35,0o77 etc..
• Hexadecimal form:An integer beginning with
0x(zero followed by letter X) for eg:
b.Floating point literals or real literals
These can be written in fractional form eg:-
13.0,.75 etc..or in exponent form
eg.,0.17E5,3.E2,6.E4
c.Complex number literals:
a+bj where a and b are
Boolean literals
• A boolean literal is used to represent one of
the two Boolean values ie.., TRUE or FALSE
Special Literal None
Python has one special literal, which is none. It is
used to indicate the absence of a value
Operators
• Operators are tokens that trigger some
computation or action when applied to
variables and other objects in an expression.
• Arithmetic operators: (+,-,*,/,%,**,//)
• Bitwise operators: (&,^)
• Shift operators: (<<,>>)
• Identity operators: (is,is not)
• Relational operators: (>,<,>=,<=,==,!=)
Operators
• Logical operators: (and,or)
• Assignment operators: (=)
• Membership operators: (in,not in)
• Arithmetic assignment operators: (/=,+=,-
+,*/,%=,**=,//=)
Punctuators
• Punctuators are symbols that are used in
programming languages to organize sentence
structures.
• Eg: ‘ “ # \ () [] {} @ , : . =