CLASS XI Informatics Practices (065) [2025-26] UNIT 2 Python
Chapter 3. Python fundamentals
Topics to be covered
» 3.1 Barebones of python/ Basic structure of python
» 3.2 Python character set
» 3.3Tokens
» 3.4 Variables and assignment
» 3.5 Precedence of operators
» 3.6 Dynamic Typing
» 3.7 Simple input and Output function
3.1 Barebones of python/ Basic structure of python
It contains various components:
1) Expressions
2) Statement
3) Comments
4) Block and Indentation
5) Function
1. Expression:-
➢ An expression is defined as a combination of constants, variables and operators.
➢ An expression always evaluate to a value.
➢ A value or a standalone variable is also considered as an expression but a standalone
operator is not an expression. Some examples of valid expression are given below:
a) B= a-10
b) Num-20.4
c) 23/3-5*7(14-2)
d) “global” + “citizen”
e) print(2* ’NO’ +3* ‘!’) o/p: NONO! ! !
In the following example ‘*’ and ‘/’ have higher precedence than ‘+’ and ‘-’.
NOTE:-
a. Parenthesis can be used to override the procedure of operator. The expression within is
evaluated first.
b. For operator with equal precedence, the expression is evaluated from left to right.
DR. UMME KULSUM [IT DEPT , PGT] 1
CLASS XI Informatics Practices (065) [2025-26] UNIT 2 Python
2. Statement:-
While an expression represents something, a statement is a programming instruction that does
something i.e. some action takes place. In python each and every line is known as statement.
Following are some examples of statements.
print (“Hello”) # this statement calls print function.
if b > 5 # this statement tests if b > 5
3. Comments:-
Comments are the additional readable information, which is read by the programmers but
ignored by the python interpreter. In python, comments begin with symbol # (pound or hash
character) and end with the end of physical line. // java , //c++,// c
There are two types of comments
a. Inline/single comments:-
The inline comments start with a ‘# ‘ in the middle of a physical line, after python code.
Sum= Num1+Num2 # Addition of two numbers.
b. Multiline comments:-
You can enter a multi-line comment in python code in two ways.
I. Add a # symbol in the beginning of every physical line part of the multi-line comments.
Example:-
# Multi-line comments are useful for detailed additional information.
# Related to the program in question.
# It helps classify certain important things.
II. Type comment as a triple-quoted multi-line string.
Example:-
“‘Multi-line comments are useful for detailed additional information related to the
program in question.
It helps classify certain important things. ”’
4. Block and Indentation:-
Sometimes a group of statement is part of another statement or function.
➢ Such a group of or more statement is called block or code-block or suite.
For example:-
if b<5:
print (“value of b is less than 5”)
print (“Thank you”)
DR. UMME KULSUM [IT DEPT , PGT] 2
CLASS XI Informatics Practices (065) [2025-26] UNIT 2 Python
Four spaces together mark the next indent level.
This is a block with all its statements at same indentation level.
Many language such as c, java etc. use symbols like curly brackets to show blocks but python
does not use any symbol for it, rather it user indentation.
5. Function :- A function is a block of code which only runs when it is called. You can pass
data known as parameters in to a function.
Example: print() , input () , def aps():
A function refers to a set of statements or instructions grouped under a name that perform
specified tasks. For repeated or routine tasks, we define a function. A function is defined once
and can be reused at multiple places in a program by simply writing the function name, i.e., by
calling that function.
3.2 Python character set:-
Character set is a set of valid character that a language can recognize.
➢ A character represents any letter, digit or any other symbol.
➢ Python supports Unicode encoding standard python has the following character set.
Letters A-z, a-z
Digits 0-9
Special symbols Space + - / * \) [ ] { } // =! = x= <,>,” , : ; % ! & # > = @ _
(underscore)
Whitespaces Blank space, tabs (), carriage return (), new line, from
feed.
Other characters Python can process all ASCII and Unicode character as
part of data or literals.
3.3Tokens:-
DR. UMME KULSUM [IT DEPT , PGT] 3
CLASS XI Informatics Practices (065) [2025-26] UNIT 2 Python
Token is the smallest unit of any programming language. It is also known as lexical unit.
Types of tokens are:
1) Keywords
2) Identifier(Names)
3) Literals/Values
4) Operators
5) Punctuators
1. Keywords:-
Keywords are those words with provides a special meaning to interpreters.
Keywords are reserved word for specific functioning.
These cannot used as identifiers, false, true, and, or, if, break, continue etc.
False class finally is return
None continue for lambda try
True def from nonlocal while
and del global not with
as elif if or yield
assert else import pass
break except in raise
2. Identifiers
Identifiers are fundamental building blocks of a program.
➢ They are used as the general terminology for the names given to different parts of the
program.
➢ In programming language, identifies are names used to identify a variable, function,
classes, object, lists, dictionaries or other entities in a program.
➢ It helps to differentiate one entity from another.
Rules for naming an identifiers in python are as follows:
A. The name should begin with an uppercase or a lowercase alphabet or an underscore
sign (_). This may be followed by any combination of characters a-z, A-Z, 0-9 or
underscore (_). Thus, an identifier cannot start with a digit.
B. It can be of any length, (however, it is preferred to keep it short and meaningful).
C. We cannot use special symbols like! , @, #, S, % etc. in identifiers.
The following are some valid identifiers.
My file, MYFILE, CHK, Z2TOZ9, DATE9_7_77, _DS, FILE_13, HJ13_JK.
The following are some invalid identities:
DATE-REC – contains special character –(hyphen).
29CLS – starting with a digit.
Break – reserved keyword.
My file – contains special character dot (.)
D. Identifiers should not be a keyword or reserved word of python.
DR. UMME KULSUM [IT DEPT , PGT] 4
CLASS XI Informatics Practices (065) [2025-26] UNIT 2 Python
False class finally is return
None continue for lambda Try
True def from nonlocal while
and del global not With
as elif if or Yield
assert else import pass
break except in raise
E. Always gives the identifiers a name that makes sense.
For example to find the average of marks obtained by a student in three subjects namely
Maths, English, marks IP and avg rather than a, b, c, or A, B, C as such alphabets.
Avg = (marksmaths + marksEnglish + marksIP) / 3.
3. Literals / values:-
Literals are often called constant values. A=”None”
Python allow the following types of literals
• String literals
• Numeric literals
• Boolean literals
• Special literals
• Literals collection
a) String literals:-
The text enclosed in quotes forms literals in python. String literals by enclosing text in
both forms of quotes-single quotes or double quotes.
In python string is of two types—
1) Single line string(terminated in one line)
A=’hello world’
2) Multiline string(multiline string)
A=’Hello world’ or A= “hello world”, \, “__” are used.
b) Numeric literals:-
Numeric value can be of three types:
1) Int (integer) -10,10
2) Float (floating point), -10.5
3) Complex (complex nos.), 3+5i, 3j+5i j is √-1, 3+5 is real number.
c) Boolean literals:-
A Boolean literals in python is used to represent one of the two Boolean values i.e. true
(Boolean true) or false (Boolean false).
➢ A Boolean literal can either have value as true or as false.
d) Special literals:-
➢ Python has one special literal, which is none.
➢ The none literal is used to indicate absence of value. It is also used to indicate
the end of lists in python.
DR. UMME KULSUM [IT DEPT , PGT] 5
CLASS XI Informatics Practices (065) [2025-26] UNIT 2 Python
X= none (no values)
e) Collection literals : Tuple(), List[ ] , Dictionary { }
4. Operators:-
➢ An operator is a symbol that performs some action when applied to
identifier/operands.
➢ Therefore, an operator requires operands to compute upon.
➢ Example c=a+b
➢ Here, a, b, c are operands and operators are ‘=’ and ‘+’ which are performing
differently.
Types of operators:-
a) Unary operators-
Unary plus (+)
Unary minus (-)
Bitwise complement (~)
Logical negation (not)
b) Binary operators:-
Arithmetic operator (+, -, *, /, //, %, **)
Relational operator (<, >, <=, >=, ==, !=)
Logical operator (and, or, not)
Assignment operator (=, /=, +=, -=, *=, /=, //=, %=, **=)
Bitwise operator (&, ^, |)
Shift operator (<<, >>)
Identity operator (is, is not)
Membership operator (in, not in)
5. Punctuators:-
In python punctuator are used to construct the program and to make balance between
instruction and statement.
Python has following punctuators:
, , #, @, {, }, (, ), [, ], “, ………
What is Constants?
A constant is an identifiers whose value cannot be changed throughout the execution of a
program whereas the variable value keeps on changing.
→ There are no constants in python, the way they exist in C and java.
→ In python, it is not possible to define constant whose value cannot be changed.
→ In python, constants are usually defined a module level and written in all capital letters
with underscores separating words but remember its value cannot be changed.
e.g.:- PI
TOTAL
MIN_VALUE
3.4 Variables and assignment:-
DR. UMME KULSUM [IT DEPT , PGT] 6
CLASS XI Informatics Practices (065) [2025-26] UNIT 2 Python
Named labels, whose values can be used and processed during program run, are called
variables. Variable is an identifier whose value can change.
For example variable age can have different value for different person.
Variable naming rules:-
Variable name should start with letter (a-z, A-Z) or underscore (_) for example- age, _age, Age.
➢ In variable name, no special characters allowed other than underscore (_).
➢ Variable are ease sensitive; age and age are different since variable names are
case sensitive.
➢ Variable name should not be a python keyword is also called as reserved words.
Creating a variable:-
Variable name should be unique in a program. Value of a variable can be string (for
example, ‘b’, and ‘global citizen’), number (for example 10, 71, 80, 52) or any combination of
alphanumeric (alphabets and numbers for example ‘b 10’) characters.
Variable definition:-
➢ A variable is not created until some value is assigned to it.
➢ A variable is defined only when you assign some value to it.
➢ Using an undefined variable in expression statement causes an error called
name error.
Variable assignment:-
➢ In python, we can use an assignment statement to create new variables and
assign specific values to them.
Gender= ‘M’
Message = ‘Keep smiling’
Price= 987.9
➢ Variable must always be assigned values before they are used in the program,
otherwise it will lead to an error. Whenever a variable name occurs in the
program, the interpreter replaces it with the value of that particular variable.
Multiple assignments:-
→ Python is very versatile with assignments.
→ Assigning some values to multiple variables in a single statement.
a=b=c=10
→ Assigning multiple values to a multiple variables.
x, y, z=10, 20, 30
x, y, z=x+1, y+2, z+5
print (x, y, z)
DR. UMME KULSUM [IT DEPT , PGT] 7
CLASS XI Informatics Practices (065) [2025-26] UNIT 2 Python
3.5 Precedence of operators:-
➢ When an expression contains more than one operator, their precedence (order or
hierarchy) determines which operator should be applied first.
➢ Higher precedence operator is evaluated before the lower precedence operator.
o Example:- s=(2+5)*(9/3)
o First parenthesis (() bracket) then /*+- will calculate if these are many parenthesis
so it will be calculated from left to right.
Operator Description
() Parenthesis (grouping)
** Exponentiation
+x, -x Positive, negative (unary +, -)
*/, //, % Multiplication, division, floor division, reminder
+, - Addition, subtraction
<, <=, >=, <>, !=, ==, is, is Comparisons (relational operator) identity operators.
not
Not x Boolean NOT
And Boolean AND
Or Boolean OR
3.6 Dynamic Typing:
A variable pointing to a values of a certain type, can be made to point to a value/object of
different type. This is called dynamic typing. Also this means that a variable can hold values of
different data types at different points in the program’s execution.
x=10
x=”Hello”
x=10.5
print(x)
output: 10
Hello
10.5
3.7 Simple input and Output Statement:
i) Input Statement: (input())
Using input function: input()
name=input(“Enter your name:”)
Enter your name:
>>> APS
# Example of input statement
# Addition from input statement
a=int(input("Enter 1st number"))
b=int(input("Enter 2nd number"))
c=a+b
print(c)
DR. UMME KULSUM [IT DEPT , PGT] 8
CLASS XI Informatics Practices (065) [2025-26] UNIT 2 Python
OUTPUT:
Enter 1st number 50
Enter 2nd number 60
110
>>> fname = input("Enter your first name: ")
Enter your first name: Arnab
>>> age = input("Enter your age: ")
Enter your age: 25
ii) Output Statement: (print())
# Example of output statement
>>> print (“Azamgarh Public School”)
>>> Azamgarh Public School
print(“ Hello, Welcome ”)
>>> Hello, Welcome
DR. UMME KULSUM [IT DEPT , PGT] 9