10.1Identifiers, Keywords, Statements and Expressions
Covers IGNOU MCS-201 §10.3, 10.4
Every program is made of names, reserved words, statements and expressions. This section sets out the rules for each, so that the rest of the unit can use them freely.
Identifiers
Rules for a valid identifier:
Rule
Valid
Invalid
Made of letters, digits and underscores _
mca_course, other_1
my-name (hyphen)
Must not start with a digit
plus1
1plus
No spaces or symbols such as !, @, #, $, %
total_marks
total marks, cost$
Must not be a keyword
class_name
class
Case-sensitive
IGNOU and Ignou are two different names
Any length
number_of_students_enrolled
Python 3 also allows letters from other alphabets (for example नाम = "Nav" is valid), but English letters are the convention.
By convention (PEP 8, Python’s style guide), variables and functions use lower_case_with_underscores, classes use CapitalisedWords, and constants use UPPER_CASE.
Keywords
A keyword is a reserved word with a fixed meaning to the interpreter; it cannot be used as an identifier. Python 3 has 35 keywords. All are lowercase except True, False and None:
False
None
True
and
as
assert
async
await
break
class
continue
def
del
elif
else
except
finally
for
from
global
if
import
in
is
lambda
nonlocal
not
or
pass
raise
return
try
while
with
yield
The list can be printed with import keyword; print(keyword.kwlist). Python also has soft keywords (match, case, type, _) that are reserved only in particular statements.
Statements and expressions
Expression
Statement
What it is
A combination of values, names and operators that produces a value
A complete instruction that Python executes
Examples
25, x, z + 25, len("abc")
x = 2, if x > 0: ..., import math, print(x)
In interactive mode
Its value is displayed
Displays nothing unless it prints
In a script
Its value is discarded unless printed
Runs normally
The parts of an expression: in x = a + 5 - b, the names a and b and the value 5 are operands, + and - are operators, and a + 5 - b is the expression; the whole line is an assignment statement.
Key takeaways
Identifiers: letters, digits, _; no leading digit; not a keyword; case-sensitive; any length.
35 keywords; all lowercase except True, False, None.
An expression evaluates to a value; a statement is an instruction.
In scripts, use print() to see values.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
State four rules for naming identifiers in Python, with one invalid example for each.
Show worked answer
(1) Only letters, digits and underscores may be used: roll-no is invalid because of the hyphen. (2) The name cannot begin with a digit: 3d_points is invalid. (3) A keyword cannot be used: while is invalid. (4) Spaces and special symbols are not allowed: total marks and rate% are invalid. Names are also case-sensitive, and there is no length limit.
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-201/data-structures-and-control-statements-in-python/identifiers-keywords-statements-and-expressions/ to read this page.