Python Programming — Basics & Syntax
Python fundamentals to advanced for interviews
100 Questions 10 Topics Take Test
Advertisement
Showing 61–70 of 100 questions in Basics & Syntax
Q.61 Easy Basics & Syntax
What does len() function return when applied to a string?
A The ASCII value of first character
B The number of characters in the string
C The memory size of the string
D The index of last character
Correct Answer:  B. The number of characters in the string
EXPLANATION

The len() function returns the number of characters (length) in a string.

Take Test
Q.62 Easy Basics & Syntax
What will be the output of: x = 5; y = 10; print(x == y)
A True
B False
C Error
D None
Correct Answer:  B. False
EXPLANATION

The comparison operator == checks if x equals y. Since 5 ≠ 10, the result is False.

Take Test
Q.63 Easy Basics & Syntax
Which of the following statements about Python tuples is correct?
A Tuples are mutable and can be modified after creation
B Tuples are immutable and cannot be modified after creation
C Tuples use square brackets for declaration
D Tuples automatically convert to lists when assigned
Correct Answer:  B. Tuples are immutable and cannot be modified after creation
EXPLANATION

Tuples are immutable sequences in Python, meaning their contents cannot be changed once created.

Take Test
Q.64 Easy Basics & Syntax
What is the correct way to create a dictionary in Python?
A d = {1: 'a', 2: 'b'}
B d = [1: 'a', 2: 'b']
C d = (1: 'a', 2: 'b')
D d = {1; 'a'; 2; 'b'}
Correct Answer:  A. d = {1: 'a', 2: 'b'}
EXPLANATION

Dictionaries in Python use curly braces with key-value pairs separated by colons.

Take Test
Q.65 Hard Basics & Syntax
What will be the output of: print({1, 2, 3} | {3, 4, 5})?
A {1, 2, 3, 3, 4, 5}
B {1, 2, 3, 4, 5}
C {3}
D {1, 2, 4, 5}
Correct Answer:  B. {1, 2, 3, 4, 5}
EXPLANATION

The | operator performs set union, combining all unique elements from both sets. Result is {1, 2, 3, 4, 5}.

Take Test
Q.66 Hard Basics & Syntax
Consider the following code:
x = [1, 2, 3]
y = x[::-1]
print(y)
What will be the output?
A [1, 2, 3]
B [3, 2, 1]
C [3, 1, 2]
D Error
Correct Answer:  B. [3, 2, 1]
EXPLANATION

The slice notation [::-1] reverses the list. [1, 2, 3] reversed is [3, 2, 1].

Take Test
Q.67 Medium Basics & Syntax
What will be the output of: print(all([True, True, True]))?
A True
B False
C 1
D None
Correct Answer:  A. True
EXPLANATION

all() returns True if all elements are True. Since all three elements are True, the output is True.

Take Test
Q.68 Medium Basics & Syntax
Which of the following code snippets will execute without raising a NameError?
A print(undefined_variable)
B x = 5; print(x)
C print(y) where y is not defined
D print(2 + undefined)
Correct Answer:  B. x = 5; print(x)
EXPLANATION

Only option B defines x before using it. Other options reference undefined variables, causing NameError.

Take Test
Q.69 Medium Basics & Syntax
What will be the output of: x = '10'; y = int(x); print(y + 5)?
A '15'
B 15
C '105'
D Error
Correct Answer:  B. 15
EXPLANATION

int(x) converts the string '10' to integer 10. Adding 5 gives 15 (integer addition).

Take Test
Q.70 Medium Basics & Syntax
What will be the output of: print('a' * 3 + 'b' * 2)?
A aaabb
B aabbb
C ababab
D ab ab
Correct Answer:  A. aaabb
EXPLANATION

'a' * 3 produces 'aaa' and 'b' * 2 produces 'bb'. Concatenating gives 'aaabb'.

Take Test
IGET
iget AI
Online · Ask anything about exams
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