Introdution To Python
Introdution To Python
WHAT IS PYTHON
Python is a high-level, interpreted and general-purpose programming language that
focuses on code readability. The syntax in Python helps the programmers to do
coding in fewer steps as compared to Java or C++.
WHO DEVELOPED PYTHON
Python was named after famous BBC comedy show namely Monty Python’s Flying
Circus. It was develop by Guido Van Rossum in 1991
FEATURES OF PYTHON
1. Easy to learn & use – It is a compact and easy to use object oriented language
with very simple syntax rule.
6. Completeness – When install Python, you get everything to do the real work.
No need to download or install additional libraries.
Python has two basic modes : Script mode & Interactive mode
Interactive mode – It is a command line shell which gives immediate result for
each statement. To start in interactive mode simply type python” without any
arguments. >>> it shows that you are in interactive mode. In this mode what
you type is immediately run. If you type 1+1, it will display 2. Interactive mode
allows you to test out and see what Python will do.
Example :- >>>2
It will print 2 on the screen
>>> ( 2*5)
It will print 10 on the screen
SCRIPT MODE
In Script mode , you will write a script and then run it. The script is saved with .py
extension.
What is Character Set?
Character set is a bunch of identifying elements in the programming language.
Letters:- A-Z, a-z
Digits:- 0 to 9
Special Symbols:- space + - / ( ) [ ] = ! = < > , ‘ “ $ # ; : ? &
White Spaces:- Blank Space , Horizontal Tab, Vertical tab, Carriage Return.
Other Characters:- Python can process all 256 ASCII and Unicode Characters.
COMMENTS IN PYTHON :Comments can be added to python scripts to
describe the purpose of statements. It start with # ( hash character) .
and Python will render the rest of the line as a comment:
Comments can be used to explain Python code. Comments starts with a #, and
Python will ignore them:
#This is a comment.
Print("Hello, World!")
Python Operators
Operators are used to perform operations on variables and values.
Python divides the operators in the following groups:
Arithmetic operators
• Addition
x=5
y=3
z=2.3
p=2.1
Print(x + y) #ans 8
Print(x+z) #ans 7.3
Print (z+p) #ans 4.4
• Division
x = 12
y=3
Print(x / y) #ans 4
• Modulus
x=5
y=2
Print(x % y) #ans 1(reminder)
Exponentiation
x=2
y=5
Print(x ** y) #same as 2*2*2*2*2 or(25)
Programs
Q1.program to enter 2 numbers and show the sum,Division,and subtraction
of those two numbers
Q2.Program to enter length and breadth of a rectangle and find area of a
rectangle
Q3Program to find square of a given number.
Q4.Program to print half of a given number
Ans- QS-1
>>>a =10
>>>b=30
>>>sum = a+b
>>>div = a/b
>>>sub = a-b
>>>Print (sum)
>>>Print (div)
>>>Print (sub)
Ans-QSNO-2
>>>length=20
>>>breadth=10
>>>area=length*breadth
>>>Print (area)
Ans-QSNO-3
>>side=20
>>Square=side*side
>>Print (square)
Ans-QS4
>>a=60
>> Half=a/2
>>Print (half)
1 MARK QUESTIONS
1. Python is an ____________ language.
a) High level b) Object oriented c)Procedural d) difficult
2. Python uses an ____________ to convert source code to object code
a) Interpreter b) Compiler c) Combination of both A &B d)
Special virtual engine
3.Python code can run on a variety of platforms, it means Python is a ______
language.
a)graphical b) cross-platform c) independent d) all of these
4.Python programs are type in
a)Interactive mode b)Script mode
c) A combination of interactive & script mode d) All of these
5.The __________ mode of Python gives instant result of typed statement.
a)Interactive mode b)Script mode
c) A combination of interactive & script mode d) All of these
6.To print the value of a variable, Python uses
a)Print statement b)Print ( ) function
c) Print statement d)Print()function
8. Python is a high level language.
9. Python’s two working modes are : Interactive mode and Script mode.
10.The shortcut key to run a Python program from script mode is F5
11.Python programs/scripts are stored in files with .py extension.
12. What is the difference between Interactive mode & Script Mode in Python?
Ans : In Interactive mode, instructions are given in Python prompt( e.g.. >>>).
Python carries out the given instruction and shows the result there itself. Where in
Script mode, Python instructions are stored in a file generally with .py extension
and are executed together in one go as a unit. The saved instructions are known as
Python script or Python program.
13. What will be the output of the following code :
# This is a sample program
# print (“such as”)
Print(“take every chance”)
Print(“Drop every fear”)
a) such as b) such as c)take every chance
take every chance take every chance drop every fear
drop every fear drop every fear
14.Who developed Python Programming Language?
a) Wick van Rossum b) Rasmus Lerdorf
c) Guido van Rossum d) Niene Stom
15. Why is Python such a widely used programming language?
a. Easy to learn
b. Portability and compatibility
c. A Broad Standard Library
d. All of the above
16. Python is a _________ programming language, which means it runs on a
variety of platforms including Windows, MacOS, Linux, and the Java
and.NET Virtual machines.
a. Cross-platform
b. Single-platform
c. Code-platform
d. None of the above
17. IDLE stands for ____________.
a. Integrated Development and Learning Environment
b. Internal Develop and Learning Environment
c. Inside Development and Learning Environment
d. None of the above.
18. A _________ is a piece of text that doesn’t impact the outcome of a
programme; it’s just a way to tell someone what you’ve done in a programme or
what’s going on in a block of code.
a. Statement
b. Comments
c. Nodes
d. None of the above
19. A _________ is a type of variable whose value cannot be changed.
a. Constant
b. Statement
c. Identifier
d. None of the above
20. Numbers with fractions or decimal points are called ________ datatype.
a. Integer
b. String
c. Float
d. None of the above
21. _________ function is used to given output in python.
a. printf()
b. print()
c. scan()
d. None of the above
22. _________ function is used to take input from the user in python.
a. Input()
b. Insert()
c. Store()
d. None of the above