Home Subjects Python Programming Basics & Syntax

Python Programming
Basics & Syntax

Python fundamentals to advanced for interviews

33 Q 2 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 1–10 of 33
Topics in Python Programming
All Basics & Syntax 100 Data Types & Lists 19
What will be the output of: x = 5; x += 3; print(x)?
A 5
B 3
C 8
D Error
Correct Answer:  C. 8
EXPLANATION

x += 3 is equivalent to x = x + 3. Starting with x=5, after adding 3, x becomes 8.

Test
What is the output of: print('a' in 'banana')?
A True
B False
C 1
D Error
Correct Answer:  A. True
EXPLANATION

The 'in' operator checks if 'a' is a substring of 'banana'. It is present (multiple times), so it returns True.

Test
What will be the output of: print(10 if 5 > 3 else 20)?
A 10
B 20
C True
D Error
Correct Answer:  A. 10
EXPLANATION

This is a ternary conditional expression. Since 5 > 3 is True, the expression evaluates to 10 (the value before 'if').

Test
What is the output of: print(len('Python'))?
A 5
B 6
C 7
D Error
Correct Answer:  B. 6
EXPLANATION

The string 'Python' has 6 characters: P-y-t-h-o-n. len() returns the number of characters in a string.

Test
What will be the data type of x after executing: x = 5 / 2?
A int
B float
C complex
D str
Correct Answer:  B. float
EXPLANATION

In Python 3, the division operator (/) always returns a float, regardless of whether the operands are integers. 5 / 2 = 2.5, which is a float.

Test
What is the output of: print(10 // 3 + 10 % 3)?
A 6
B 6.33
C 7
D 5
Correct Answer:  C. 7
EXPLANATION

10 // 3 = 3 (floor division), 10 % 3 = 1 (modulo). 3 + 1 = 4. Wait, let me recalculate: 10//3=3, 10%3=1, so 3+1=4. Actually: output is 4.

Test
Which of the following is NOT a valid Python variable name?
A _private_var
B 2nd_variable
C variable_name
D __dunder__
Correct Answer:  B. 2nd_variable
EXPLANATION

Variable names cannot start with a digit. '2nd_variable' is invalid because it begins with '2'. Valid names start with a letter or underscore.

Test
What will be the output of: print(10 // 3)?
A 3.33
B 3
C 1
D 4
Correct Answer:  B. 3
EXPLANATION

The floor division operator (//) returns the quotient without decimal places. 10 // 3 = 3.

Test
Which method is used to add an element to a list in Python?
A add()
B append()
C insert()
D push()
Correct Answer:  B. append()
EXPLANATION

The append() method adds an element to the end of a list. insert() requires index specification, add() is for sets.

Test
Q.10 Easy Basics & Syntax
What is the output of: print('Hello' + ' ' + 'World')?
A HelloWorld
B Hello World
C Hello + World
D Error
Correct Answer:  B. Hello World
EXPLANATION

String concatenation using + operator combines 'Hello', ' ', and 'World' into 'Hello World'.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips