Python Fundamentals
Python Fundamentals
Computer Science
Class XI ( As per
CBSE Board)
Python
Fundamentals
New
Syllabus
2023-24
Introduction
Python 3.0 was released in 2008. Although this version is
supposed to be backward incompatibles, later on many of its
important features have been back ported to be compatible
with version 2.7
Python Character Set
A set of valid characters recognized by python. Python uses the traditional
ASCII character set. The latest version recognizes the Unicode character set.
The ASCII character set is a subset of the Unicode character set
Letters :– A-Z,a-
z Digits :– 0-9
Special
symbols :–
Special symbol
available over
keyboard
White spaces:– blank space,tab,carriage return,new line, form feed
Input and Output
var1=‘Computer Science'
var2=‘Informatics
Practices' print(var1,' and
',var2,' ) Output :-
Computer
Science and
Informatics
Practices
as finally or
continue if return
del in while
elif is with
except
Identifiers
A Python identifier is a name used to identify a variable,
function, class, module or other object.
*An identifier starts with a letter A to Z or a to z or an
underscore (_) followed by zero or more letters, underscores
and digits (0 to 9).
* Python does not allow special characters
* Identifier must not be a keyword of Python.
* Python is a case sensitive programming language.
Thus, Rollnumber and rollnumber are two different identifiers
in Python.
Some valid identifiers : Mybook, file123, z2td, date_2, _no
Some invalid identifier : 2rno,break,my.book,data-cs
Identifiers-continue
Some additional naming conventions
1. Class names start with an uppercase letter. All other
identifiers start with a lowercase letter.
\\ Backslash (\)
Types of Operators
1. Arithmetic Operators.
2. Relational Operators.
3. Assignment Operators.
4. Logical Operators.
5. Bitwise Operators
6. Membership Operators
7. Identity Operators
Operators continue
1. Arithmetic Operators
Arithmetic Operators are used to perform arithmetic operations like
addition, multiplication, division etc.
Operators Description Example
//= Perform floor division on 2 numbers and assigns the result to left operand. a//=b
**= calculate power on operators and assigns the result to left operand. a**=b
Operators continue
4. Logical Operators
Logical Operators are used to perform logical operations on the
given two variables or values.
a=30
b=20
if(a==30 and b==20):
print('hello')
Output :-
hello
Operators continue
6. Membership Operators
The membership operators in Python are used to validate whether a
value is found within a sequence such as such as strings, lists, or
tuples.
Operators Description Example
not in return true if value does not exists in the sequence, else false. a not in list
E.g.
a = 22
list = [22,99,27,31]
In_Ans = a in list
NotIn_Ans = a not in list
print(In_Ans)
print(NotIn_Ans)
Output :-
True
False
Operators continue
7. Identity Operators
Identity operators in Python compare the memory locations of two objects.
Operators Description Example
is returns true if two variables point the same object, else false a is b
is not returns true if two variables point the different object, else false a is not b
e.g.
a = 34
b=34
if (a
is b):
pri
nt('
bot
ha
an
db
has
sa
me
ide
ntit
Punctuators / Delimiters
Used to implement the grammatical and structure of a Syntax.Following
are the python punctuators.
Barebone of a python program
#function definition comment
def keyArgFunc(empname, emprole):
print ("Emp Name: ", empname) Function
print ("Emp Role: ", emprole) indentation
return;
A = 20 expression
print("Calling in proper sequence")
keyArgFunc(empname = "Nick",emprole = "Manager" )
print("Calling in opposite sequence") statements
keyArgFunc(emprole = "Manager",empname = "Nick")
fun()
print(x) #error
will be shown
2. Global
Variable
x=8
def fun():
print(x)
# Calling
variable ‘x’
inside fun()
fun()
Dynamic typing
print('hell
o India')
Output :-
h
ello India
print(‘Computer',‘Science')
print(‘Computer',‘Science',sep=' & ')
print(‘Computer',‘Science',sep=' & ',end='.')
Output :-
Computer