Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Chapter 1: Python Revision Tour

Practical 1

Introduction:
Python programming language, developed by Guido Van Rossum in early 1990s, has become
a very popular programming language among beginners as well as developers.

Tokens:
The smallest individual unit in a program is known as a Token or a lexical unit.
Python has following tokens:
i) Keywords:
A keyword is a word having special meaning reserved by programming language.
Python programming language contains the following keywords:

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

ii) Identifiers:
Identifiers are the names given to different parts of the program namely variables,
objects, classes, functions, lists, dictionaries and so forth.
The naming rules for Python identifiers can be summarized as follows:
a) Variable names must only be a non-keyword word with no spaces
between.
b) Variable names must be made up of only letters, numbers, and underscore
(_)
c) Variable names cannot begin with a number, although they can contain
numbers

iii) Literals/Values:
Literals are data items that have a fixed/constant value. Python allows several
kinds of literals, which are being given below:
a) String Literals:
String literals is a sequence of characters surrounded by quotes (single or
double or triple quotes). Strings can either be single line strings or multi-line
strings
• Single line strings must terminate in one line i.e., the closing
quotes should be on the same line as that of the opening quotes.

• Multiline 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
backslash is needed at the end of intermediate lines.

1
# PRG1 Demonstrates types of strings in Python

STR1= 'Hello World'


STR2='''Hello
World
There I COME!!!
Cheers.'''
STR2 ="Hello\
world\
There I COME!!!\
Cheers."
STR3='''Hello
World
There I COME!!!
Cheers.'''
print('_'*52)
print(STR1)
print('_'*52)
print(STR2)
print('_'*52)
print(STR3)
print('_'*52)

Output:

You might also like