CLASS: XI CBSE
CHAPTER: 6
Introduction:
Getting Started With Python
Python programming language was developed by Guido Van Rossum in February 1991. It has
influence of two programming language.
i. ABC language
ii. Modula-3
It is a powerful and easy to learn Object Oriented Programming Language. It is an interpreter
based programming language.
Advantages of Python:
1. Easy to Use:
2. Expressive Language
3. Interpreter Based Language
4. Cross Platform Language: The program made in one machine (Eg: Windows) an be
easily run in other machines (Eg: linux, Mac),etc
5. Free And Open Source Language: It can be downloaded easily in free of cost from its
official website. Its codes can also be downloaded from internet.
6. Lots of Libraries
Disadvantages of Python:
1. It is not the fastest language.
2. Weak data type binding.
3. Weak Version Compatibility
4. Incompetent Libraries as compared to other languages.
Distribution In Python:
i. Anaconda
ii. CPython
iii. ActivePython
iv. Enthought Canopy
v. WinPython
Popular IDE’s of Python
i. Spyder IDE
ii. PyCharm IDE
iii. IDLE (Default)
iv. Jupyter Notebook
Working with default IDE (CPython):
Modes of Working:
Cpython provides two modes:
i. Command Mode/ Interactive Mode
ii. Script Mode:
Interactive Mode Script Mode
i. It is python prompt >>> It is a python file saved with .py extension.
ii. It is fast in execution. It is bit slow in execution.
iii. Program cannot be saved in Program can be saved in script mode
interactive mode
iv. Useful for small code Useful for more number of statements.
v. By default python opens in It gets open by clicking on File->New File
Interactive mode
vi. Program can be run by pressing Program can be run by pressing F5 shortcut
Enter key key.
Print Function In Python
It displays the result and message in the output screen. It has two named
argument
i. sep: It works in a print statements and used as a separator in a values.
By default it is space.
ii. end: It control the cursor position after printing is done. By default
cursor position is new line(\n).
Example:
x,y=10,20
print(x,y,sep=';',end=' ')
print(y)
Output:
10;20 20
input() Function
input():
It is used to take input from the user and store it in a variable.
x=input('Message')
Eg:
x=input('Enter a value')
It stores the value in x.
The default data type of input function is string.
It order to convert string to other type, following function is used
int(): to convert into integers.
float(): to convert into floating value
Q. Write a statement that takes input of number from the user
x=input('Enter a number')
x =int(x) # if is floating then it gives error
x=float(input('Enter a number'))
print(): It is used to display the message and the value of variable in the
output screen.
'''
#Displaying a message
print('This is my first program') #message are written in quotes
#Diplaying a value of variable
x=10
y=20
print(x,y) #variable are written without quotes
#More than one values are seperated by ,
'''
Q. Write a statement that displays the message
The value of x is 10 and y is 20
'''
x=100
y=120
print('The value of x is',x,'and y is',y)
x=10 and y=20
print('x=',x,'and y=',y)
Questions
Q1. What is the output of the following code?
x=int(input('Enter a number')) #20
y=input('Enter a number') #20
print(x+x)
print(y+y)
Q2. Consider a statement:
x=int(input('Enter a number'))
print(x)
What will be the output if the input is
(a) 34
(b) 20.9
(c) abc
Q3. Write a statement that input a floating value and store it in variable z.
Q4. What is the result on writing:
(a)
x=10
y=90
print('The sum of',x,'and',y,'is',x+y,sep='$')
(b)
x=10
y=20
print('x=',x,sep='#',end='$')
print('y=',y,sep='@',end='!!!')
(c)
x=90
y=190
__________
Fill in the blanks with suitable print statement so that the output is
x$90y$190
(i) print(x,90,y,190,sep="$")
(ii) print('x',x,'y',y,end='$')
(iii) print(x,'x',y,'y',sep='$')
(iv) print('x',x,'y',y,sep='$')