0% found this document useful (0 votes)
9 views59 pages

21.03.plus Two Cs Review of Python QP Best

The document provides a review of Python basics, covering topics such as data types, operators, and syntax. It includes questions and answers related to mutable and immutable types, valid literals, dictionary operations, and string manipulations. Additionally, it discusses concepts like loops, conditional statements, and the differences between certain operators.

Uploaded by

moomooizzywizzy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views59 pages

21.03.plus Two Cs Review of Python QP Best

The document provides a review of Python basics, covering topics such as data types, operators, and syntax. It includes questions and answers related to mutable and immutable types, valid literals, dictionary operations, and string manipulations. Additionally, it discusses concepts like loops, conditional statements, and the differences between certain operators.

Uploaded by

moomooizzywizzy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

REVIEW OF PYTHON

BASICS
Which of the following is an immutable data type?
a) List
b) Dictionary
c) Tuple
d) Set
List (❌ Mutable): Lists can be modified after creation (elements can
be added, removed, or changed).

Dictionary (❌ Mutable): Dictionaries allow modifications like adding


or updating key-value pairs.
Tuple (✅ Immutable): Tuples cannot be changed after creation (no
modifications allowed).

Set (❌ Mutable): Sets allow adding and removing elements


dynamically.
What is the output of print(2**3)?
a) 6
b) 8
c) 9
d) None
In Python, the ** operator represents exponentiation (power).
Which of the following is not a valid Literal in Python:

a) True b) 0x2B
c) -2.5E-3 d) YUV
(a) True ✅
This is a Boolean literal in Python.
True and False are the only Boolean literals.

(b) 0x2B ✅
This is a hexadecimal integer literal (base 16).
0x prefix denotes hexadecimal notation.
0x2B = (2 × 16 + 11) = 43 in decimal.

(c) -2.5E-3 ✅
This is a floating-point literal in scientific notation.
-2.5E-3 means −2.5×10−3=−0.0025−2.5×10−3=−0.0025, which is valid.

(d) YUV ❌ (Invalid)


YUV is not a valid Python literal unless defined as a string ("YUV" or 'YUV').
If YUV is used without quotes, Python will treat it as a variable, and if not defined, it
will raise an error.
What will be the output of the python code given below:
P = [20, 50]
Q = [5, 8]
P.extend(Q)
print(P)

a) [20, 50, 5, 8] b) [20, 50, [5, 8]]


c) [20, 50] d) [5, 8, 20, 50]
Consider the following string declaration in python:
S = ‘PROCEDURE’
Which of the following statements will produce output as ‘RUDE’?

a) print(S[4:8]) b) print(S[-2:3:-1])
c) print(S[-2:-6]) d) print(S[7:-5:-1])
Which of the following statement(s) will not create dictionary D?

a) D = {2:2, 'A':'A’} b)D = {(2,):(2,),('A'):('A')}


c) D = {[2]:[2], ['A']:['A’]} d) D = {(2):[2], ('A'):['A']}
Which of the following statement would give an error during execution
of the following code?
tup = (4, ‘CMA', 5.5, 3)
print(tup[2]+100) #Statement 1
print(max(tup)) #Statement 2
print(tup.index(5.5)) #Statement 3
del tup #Statement 4

a) Statement 1 b) Statement 2
c) Statement 3 d) Statement 4
What will be the output of the following code?
L = [2, 4, '2', 2.0, [2, 20], ‘RT5']
print(L.count(2))

a) 1 b) 2
c) 3 d) 4
State True or False:
“Mutable data types in python allows changes at the same memory
location”
State True or False:
“Variable declaration is implicit in Python.”
Which of the following is the correct output for the execution of the
following Python statement?
print(5 + 3 ** 2 /2)
(A) 32 (B) 8.0
(C) 9.5 (D) 32.0
Select the correct output of the code:
a = "Good bye 2022. Welcome 2023"
a = a.split('0')
b = a[1] + ". " + a[0] + ". " + a[2]
print (b)
(a) 22. Welcome 2. Good bye 2. 23
(b) Good bye 2. 2322. Welcome 2.
(c) 22. Welcome 2. 232. Good bye
(d) 22. Good bye 2. 23 Welcome 2.
Given the following dictionaries
dict_exam={"Exam":"AISSCE", "Year":2023}
dict_result={"Total":500, "Pass_Marks":165}
Which statement will merge the contents of both dictionaries?

(a) dict_exam.update(dict_result) (b) dict_exam + dict_result


(c) dict_exam.add(dict_result) (d) dict_exam.merge(dict_result)
If a=1,b=2 and c= 3 then which statement will give the output as : 2.0
from the following:

a) >>>a%b%c+1
b) >>>a%b%c+1.0
c) >>>a%b%c
d) a%b%c-1
The ___________ statement is an empty statement in Python.
Which of the following is not a keyword?
(a) eval (b) assert (c) nonlocal (d) pass
What will be the output for the following Python statements?
D= {“Amit”:90, “Reshma”:96, “Suhail”:92, “John”:95}
print(“John” in D, 90 in D, sep= “#”)
(a) True#False
(b)True#True
(c) False#True
(d) False#False
What will the following Python statement evaluate to?

print (5 + 3 ** 2 / 2)

(a) 32
(b) 8.0
(c) 9.5
(d) 32.0
Identify the errors in the following code:
MyTuple1=(1, 2, 3) #Statement1
MyTuple2=(4) #Statement2
MyTuple1.append(4) #Statement3
print(MyTuple1, MyTuple2) #Statement4

(a) Statement 1
(b) Statement 2
(c) Statement 3
(d) Statement 2 &3
State whether True or False: Variable names can begin with the _
symbol.
Identify which of the following is an invalid data type in Python:

(a) int (b) float (c) super (d) None


1. Numeric Types

int → Integer values (e.g., 10, -5, 1000)


float → Floating-point numbers (e.g., 10.5, -3.14, 2.0)
complex → Complex numbers (e.g., 2 + 3j, -1 - 4j)

2. Sequence Types

str → String (e.g., "Hello", 'Python')


list → Ordered, mutable collection (e.g., [1, 2, 3, "hello"])
tuple → Ordered, immutable collection (e.g., (1, 2, 3, "hello"))
3. Set Types

set → Unordered collection of unique elements (e.g., {1, 2, 3, "apple"})


frozenset → Immutable version of set (e.g., frozenset({1, 2, 3})
4. Mapping Type

dict → Key-value pairs (e.g., {"name": "John", "age": 25})

5. Boolean Type

bool → Represents True or False values


6. None Type

None → Represents the absence of a value


Consider the following code:

dict1 = {‘Mohan’: 95, ‘Ram’: 89, ‘Suhel’: 92, ‘Saritha’: 85}

What suitable code should be written to return a list of values in dict1 ?


Consider the following expression:

not True and False or not False

Which of the following will be the output:

a) True
b) False
c) None
d) NULL
Select the correct output of the following code:
>>>str1 = ‘India is a Great Country’
>>>str1.split(‘a’)

(a) [‘India’,’is’,’a’,’Great’,’Country’]
b) [‘India’, ’is’, ’Great’, ’Country’]
c) [‘Indi’, ’is’, ’Gre’, ’t Country’]
d) [‘Indi’, ’is’, ’Gre’, ’t’, ‘Country’
Which of the following will be the output of the code:
mySubject = “Computer Science”
print(mySubject[:3] + mySubject[3:])
a) Com
b) puter Science
c) Computer Science
d) Science Computer
Find the output of following code :
p = 10
q = 20
p *= q // 3
p = q ** 2
q += p
print(p, q)
Which statement will give the output as : True from the following :
a) >>>not -5
b) >>>not 5
c) >>>not 0
d) >>>not(5-1)
The input() function always returns a value of ……………..type.

a) Integer
b) float
c) string
d) Complex
To include non-graphic characters in python, which of the following is
used?
a. Special Literals
b. Boolean Literals
c. Escape Character Sequence
d. Special Literal – None
Which of the following operation is supported in python with respect
to tuple t?
a) t[1]=33
b) t.append(33)
c) t=t+t
d) t.sum()
Which of the following is not a valid identifier in Python?
a)Empuran b) _1st c) Hello_Dady d) Maya nadhi
What will be the output of the following statement ?

print(6+5/4**2//5+8)
(A) –14.0
(B) 14.0
(C) 14
(D) –14
Select the correct output of the code :
S = "text#next"
print(S.strip("t"))

(A) ext#nex
(B) ex#nex
(C) text#nex
(D) ext#next
What are mutable and immutable data types? Give examples.

Mutable (Can be modified): list, dict, set


Immutable (Cannot be modified): int, float, tuple, str
Consider the statements given below and then choose the correct
output from the given options :
Game="World Cup 2023"
print(Game[-6::-1])
(A) CdrW
(B) ce o
(C) puC dlroW
(D) Error
For the following Python statement :
N = (25) What shall be the type of N ?
(A) Integer
(B) String
(C) Tuple
(D) List
Predict the output of the following code :
d = {"IND": "DEL", "SRI": "COL", "CHI": "BEI"}
str1 = ""
for i in d:
str1 = str1 + str(d[i]) + "@"
str2 = str1[:-1]
print(str2)
(a) Given is a Python string declaration:
str1="!!Welcome to Python!!"
Write the output of:
print(str1[::-2])

(b) Write the output of the code given below:


dict1 = {"name": "Suman", "age": 36}
dict1['age'] = 27
dict1['address'] = "Chennai“
print(dict1.keys())
Rewrite the following code in Python after removing all the syntax
errors. Underline each correction made by you in the code.
num = 10
for x in range[0, num]:
if x in not [3, 5]:
print(x*4)
else if x = = 8:
print(x+3)
else:
a =+ x
Write single python statement to perform the following tasks:
Given a string S = "INDIA AND INDIANS ARE GREAT"
(i) Write python statement to display number of times ‘INDIA’ appears
in the above string.
(ii) Write python statement to create a new string to add word
‘REMAIN’ in place of ‘ARE’ and display the string as:
INDIA AND INDIANS REMAIN GREAT
Differentiate between ‘is’ and == operators.
Explain the difference between break and continue statements.

break: Terminates the loop completely.

continue: Skips the current iteration and continues with the next one.
Rewrite the following code in python after removing all syntax error(s).
Underline each correction done in the code.
250 = Number
WHILE Number<=1000:
if Number=>750:
print(Number)
Number=Number+100
else
print(Number*2)
Number=Number+50

You might also like