Python Unit 2 (2marks)
Python Unit 2 (2marks)
QUESTIONS WITH
ANNA UNIVERSITY 2 MARK
ANSWERS
Example:
>>>n=10
>>>name-Jovita"
>>>P[=3.14
3. List any four built in data types in Python. (AUApr/ May 2022, R2021)
Point type, and
The built in data types are, Numbers (Integer type, Floating
Complex type), String, List, Tuple, Set, Boolean and None types.
2022, R2021)
4. How do you assign a value to a tuple in Python? (AUApr/ May
Data Types, Expressions, Satements 125
1.
The compiler takes a program as a Interpreter translates program
whole and translates it. statement by statement.
Keywords are reserved words that have predefined meanings in python. They
cannot be used as ordinary identifiers and must be spelled exactly as they are
written python3 has 33 keywords.
Keywords of Python
False class finally return
Example:
The interpreter mode is the mode where the scripted and finished -py files are
run in the Python interpreter.
The interactive mode is a command line shell which gives immediate feedback
for each statement, fed statements in active memory. As new lines are fed into
the interpreter. the fed program is evaluated both in part and in whole.
15. Name five primitive data types in Python.
Five primitive data types in Python are: Numbers, String, List, Tuple and
Dictionary.
l6. What does immutable' mean: which data type in python are immutable?
Progranmming
128 Problem Solving and Python said to be
in place is
An obiect whose state or value cannot be changed one that cannot
Sequence is
immutable type. So, a sequence that is immutabl
change. For example. Strings and Tuples ae immutable.
escape sequence in Python.
17. What are escape sequences? Write any four
consists of backslash
followed
Escape sequences are non printable characters. It
by acharacter both are enclosed within single quotes.
Backslash(\)
Single quote(')
Double quote(")
\a ASCII Bell (BEL)
18. Define Value.
A value is the basic units of data. like a number or a string tnat a program
manipulates.
ABoolean type represents special values True and False. The most common
way to produce a Boolean value iswith a relational operator
21. How can you create a complex literal in Python?
Complex literals can be created by using the notationx + yj where x is the real
component and y is the imaginary component. For example, >>> 1j * 1jwhich
produces the result as: (-1+0j).
22. What is a variable?
Avariable is an identifier, which holds a value. In programming, we assign a
Value to a variable. Technically, a varjable is a reference to a computer
memory, where the value is stored.
Data Types, Expressions, Statements 129
i) If the argument is a sequence (string, list or tuple), the result is a tuple wth
the elements of the sequence:
>>>t=tuple("Jovita')
>>>(a',e','",o,'u')
'a'
>>>|3]
Data Types, Expressions, Statements 131
>>>[1:3]
('e', i)
30. Give the precedence of operators in python.
Parentheses have the highest
precedence and can be used to force an
expression to evaluate in the order.
Example: 5*(9 - 3) = 30 since
expressions in
first. parentheses are evaluated
" Exponentiation has the next highest precedence.
Example: I +2**3 =9, not 27 and
2 * 3**2 =18, not 36.