Answer Key
UNIT – 2 (Introduction to Python Programming)
2 Marks
1.Define python
Python is an object-oriented, high level language, interpreted
Dynamic and multipurpose programming language.
2. Give the features of python.
Easy to Use
Expressive Language
Interpreted Language
Free and Open Source
Object-Oriented language
3. State about python interpreter.
The machine that translates and runs Python code is called the Python Interpreter:
There are two ways namely interactive mode and script mode. The >>> is called the
Python prompt.
4. Compare interactive mode and script mode.
In interactive mode, type python expressions in the Python Interpreter window and the
results are shown immediately.
In script mode, type program in a file and use the interpreter to execute the contents of
the file. Such a file is called a script.
5. Define value and variable in python.
value
A value is one of the fundamental things—like a letter or a number—that a program
manipulates.
variable
A variable is a name that refers to a value. The assignment statement gives a value to a
variable. Eg: >>> n = 17
6. List the standard data types in python.
Python has five standard data types:
Integer
, Float
Strings
List
Tuples
Boolean
7. Quote about python strings.
Strings in Python are identified as a contiguous set of characters represented in the
quotation marks.
Python allows for either pairs of single or double quotes. Subsets of strings can be taken
using the slice operator ([ ] and [:] ) The plus (+) sign is the string concatenation operator
and the asterisk (*) is the repetition operator. Eg:str = 'Hello World!'
8. List the features of ‘ lists’ in python
A list contains items separated by commas and enclosed within square brackets ([]).
The values stored in a list can be accessed using the slice operator ([ ] and [:]) with
indexes starting at 0 in the beginning of the list and working their way to end -1. The plus
(+) sign is the list concatenation operator, and the asterisk (*) is the repetition operator.
For example :
–
list = [ 'abcd', 786 , 2.23,'john', 70.2 ] print list[0]
o/p
a
b
c
d
9. Differentiate between list and tuple.
The main differences between lists and tuples are: Lists are enclosed in brackets ( [ ] )
and their elements and size can be changed,
while tuples are enclosed in parentheses ( ( ) ) and cannot be updated. Tuples can be
thought of as read-only lists.
10. What are keywords?
Keywords are the reserved words in Python. We cannot use a keyword as variable name,
function name or any other identifier.
In Python, keywords are case sensitive. There are 33 keywords in Python.
Eg: False, class, finally, return
11.Define expressions.
An expression is a combination of values, variables, operators, and calls to functions.
If you type an expression at the Python prompt, the interpreter evaluates it and displays
the result:
>>> 1 + 1=2
, 12. Quote about statement.
A statement is an instruction that the Python interpreter can execute.
When you type a statement on the command line, Python executes it. Statements don‘t
produce any result. For example, a = 1 is an assignment statement. if statement, for
statement, while statement etc. are other kinds of statements.
13. Label operators which python support?
Arithmetic Operators
Comparison (Relational) Operators
Assignment Operator
Logical Operators
Bitwise Operators
Membership Operators
Identity Operator
14. What is an Arithmetic operator?
Arithmetic operators are used to perform mathematical operations like addition,
subtraction, multiplication etc.
The operators are: +,-,/,%,*,**
15. Summarize is the use of comparison operator.
Comparison operators are used to compare values.
It either returns True or False according to the condition.
>,<,>=,<=,==,!=
16. Infer about logical operators and Bitwise operators.
Logical operators are the and, or, not operators. Bitwise operators act on operands as if
they were string of binary digits.
It operates bit by bit, hence the name. The operators are:&,|,`^,>>,<<
17. State about assignment statements.
Assignment operators are used in Python to assign values to variables.a = 5 is a simple
assignment operator that assigns the value 5 on the right to the variable a on the left.
Eg:x=44
18. Mention the features of identity operators?
The is and is not are the identity operators in Python. They are used to check if two
values (or variables) are located on the same part of the memory.
Two variables that are equal does not imply that they are identical.
19. Give the characteristics of membership operator?
The membership operators are in and not in. They are used to test whether a value or
variable is found in a sequence (string, list, tuple, set and dictionary).
In a dictionary we can only test for presence of key, not the value.