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 11–20 of 33
Topics in Python Programming
All Basics & Syntax 100 Data Types & Lists 19
Q.11 Easy Basics & Syntax
Which of the following is the correct syntax for a Python comment?
A // This is a comment
B
C # This is a comment
D /* This is a comment */
Correct Answer:  C. # This is a comment
EXPLANATION

Python uses the hash symbol (#) for single-line comments. The other syntaxes are used in other programming languages.

Test
Q.12 Easy Basics & Syntax
Consider the code: num = '123'. What will int(num) return?
A 123.0
B 123
C '123'
D Error
Correct Answer:  B. 123
EXPLANATION

int(num) converts the string '123' to the integer 123. The result is an integer type.

Test
Q.13 Easy Basics & Syntax
What does the len() function return when applied to a string 'India'?
A 4
B 5
C 6
D Error
Correct Answer:  B. 5
EXPLANATION

The string 'India' has 5 characters (I, n, d, i, a), so len('India') returns 5.

Test
Q.14 Easy Basics & Syntax
What will be the result of executing: print(type(5.0))?
A
B
C
D
Correct Answer:  B.
EXPLANATION

5.0 is a floating-point number, so type(5.0) returns <class 'float'>.

Test
Q.15 Easy Basics & Syntax
In Python, which of the following is an immutable data type?
A List
B Dictionary
C Tuple
D Set
Correct Answer:  C. Tuple
EXPLANATION

Tuples are immutable in Python, meaning their elements cannot be changed after creation. Lists, dictionaries, and sets are all mutable.

Test
Q.16 Easy Basics & Syntax
What will be the output of: print(type(3.14))
A
B
C
D
Correct Answer:  B.
EXPLANATION

3.14 is a floating-point number, so type() returns <class 'float'>.

Test
Q.17 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.

Test
Q.18 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.

Test
Q.19 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.

Test
Q.20 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.

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