2024-2025-Class XI-COMPUTER SCIENCE-Chapter 1-AW
2024-2025-Class XI-COMPUTER SCIENCE-Chapter 1-AW
Learning Objective:
Python Introduction
The language founded in the year 1991 by the developer Guido Van Rossum, a Dutch programmer and
principal author of Python programming language.
Python is the best choice for software professionals and for IT organisation because of its multi
dimension programming paradigms.
1.1 WHY COMPANIES PREFER PYTHON?
Python is the top most programming language and best choice for programmers in the recent years
over other programming languages like C, C++ and Java and is widely used by the programmers. The language
has undergone a drastic change since its release 25 years ago as many add-on features are introduced.
The programmers of top most companies using Python as it has created a bench mark for itself in the
software development, some of key attributes are.
Advantages of Python
✓ INTERACTIVE
✓ PORTABLE
✓ HIGH LEVEL
✓ EASY-TO-LEARN
✓ EASY-TO-READ
✓ ROBUST
ii) MOBILE DEVELOPMENT: It’s not a good choice mobile development; it is excellent at server side and
is being used to develop server side applications.
1.3 TRANSLATORS(Important)
Translators are the programs and are used to convert one language form in to another language form.
There are 2 types of translators exists
1
i) Compilers
ii) Interpreters
1.3.1 COMPILERS
Compilers are the system programs used to convert high level language to machine level language in
one go.
Source code is the code in python.
1.3.2 INTERPRETER
Interpreters are also fall under category of system softwares used to convert high level language to machine
level language line by line.
3
FUNDAMENTALS OF PYTHON PROGRAMMING
Learning Objective:
KEYWORDS
IDENTIFIERS
TOKENS LITERALS
OPERATORS
PUNCTUATORS
5
Size of string1 is 11. When
escape sequence \a (bell) is
introduced in string2 then size
of the string increased to 1 that
is 12
6
2.7 SPECIAL LITERAL None(IMP)
The None literal is used to represent absence of
value in a python program.
For example: x= None
2.8 VARIABLES:
These are identifiers used to store values, the variables value changes during the execution.
Some of valid variables are:
>>>Stud_marks=67
>>>Cost=859
Once these variables are assigned a value during execution values may be altered hence these are called
variables which can vary during run.
>>>Stud_marks=85
>>>Cost=850
2.10 COMMENTS
Whenever explanation for particular statement in a program is needed comments are inserted.
Comments are non-executable statements used in program.
7
Single line Comment: it start with the pound character, # , and extends to the end of same line.
Example #this is a comment.
Multiline Comment: Multiline comments extend more than 1 line. Comments included in ‘’’ ‘’’ triple
quotes are called multiline comments.
This is also known as docstring.
Example ‘’’This is a comment.
Multiline comments uses
This is another comment’’’ triple quotes(‘’’) and are also
called as docstrings
Example 2:
>>>X,Y=10,7
>>>A,B,C=X+Y,Y-3,X+12
>>> # Multiple expressions assigning to multiple variables also
>>> #possible in python.
>>> #Now A holds 17, B holds 4 and C holds 22
>>> x=10
>>> y=3
>>> x,y=x+2,y+x First x+y will be evaluated then
>>> x the value of is incremented by
12 2. Right to left.
>>> y
13 8
2.14 DYNAMIC TYPING
Change of data type from one type to another is called type casting. If change of data type takes place
while execution is called Dynamic Typing.
>>> x=10
x holds value 10. It is an integer
>>> print(x)
data type. once string is assigned
10
x changes its data type from
>>> x=”Computers”
integer to string, this technique is
>>> print(x)
called dynamic typing.
Computers
9
(f) What is an escape sequence? List any two escape sequences.
Ans Escape sequences are special characters or symbols used in conjunction with output statement.
These denote some functionality while generating output
\a – bell
\n – new line
(g) What is the difference between interactive mode and script mode in Python?
Ans Python has two basic modes: script and interactive. The normal mode is the mode where the
scripted and finished .py files are run in the Python interpreter. Interactive mode is a command
line shell which gives immediate feedback for each statement, while running previously fed
statements in active memory.
(h) Which of the following are invalid identifiers?
abc_d, break, 1rak, doc14, a2bc5, _punc, ray.dat
Ans break, 1rak, ray.dat are invalid identifiers.
(i) Out of the followings, find those identifiers, which cannot be used for naming Variables,
Functions in a Python programming language:
Roll#No, continue, True, 41stno, _v1, No_2, false, Var1
Ans Roll#No, continue, True, 41stno.
10
Python Fundamentals
LEGENDS
11
2. What will be the output produced by the following?
x, y = 2, 6
x, y = y, x+2
print (x, y)
3. What is the output of the following:
p1,q1,r1=2,3,4
r1,q1,p1 = p1+2,q1–2,r1+2
print (r1,q1,p1)
4. Predict the output:
x=34
x+=x–x ( x=x+x-x)
print(x)
5. What is the output of the following?
x,y=567,849
x,y=y,x+2
print(y,x)
6. What is the output of the following?
x,y=7,2
x,y,x=x+1,y+3,x+10
print(y,y,x)
7. Find the error in the following code and write the corrected code.
temp=90
a=12
print(“x=”,x)
print (temp)
b=a+b
print( a And b)
8. What will be the output produced by following code?
x=20
x=x+5
x=x-10
print(x)
x,y=x-1,50
print (x,y)
9. Give the output of following code construct:
print(” Fun”,”here”,sep=”@”,end=”.”)
print(”computer programming is \t fun”)
print(“Python \n Programming”)
***
12