Python Data Types

Which of the following is an immutable data type in Python?

List
Tuple
Set
Dictionary

Explanation:

Tuples are immutable, while lists, sets, and dictionaries are mutable.

Python variable assignment

Which of the following is the correct way to assign a value to a variable in Python?

int x = 10;
x = 10
10 -> x

Explanation:

The correct option is: Option A

Python print function

Which of the following is the correct way to print "Hello World" in Python 3?

print "Hello World"
echo "Hello World"
print("Hello World")

Explanation:

The correct option is: Option C

Python data types

What is the data type of the value True in Python?

int
bool
string

Explanation:

The correct option is: Option B

Python list indexing

If mylist = [10,20,30], what is mylist[1]?

10
30
20

Explanation:

The correct option is: Option A

Python string concatenation

Which operator is used to concatenate strings in Python?

*
+
-

Explanation:

The correct option is: Option C

Python comments

Which symbol is used to begin a comment in Python?

//
#
/* */

Explanation:

The correct option is: Option B

Python function definition

Which keyword is used to define a function in Python?

def
func
function

Explanation:

The correct option is: Option A

Python indentation

In Python, indentation is used for:

Defining code blocks
Comments
Variable declaration

Explanation:

The correct option is: Option C

Python division operator

What is the result of 7 // 2 in Python?

3.5
3
4

Explanation:

The correct option is: Option A

Python boolean operator

Which of the following is a boolean operator in Python?

PLUS
AND
CONCAT

Explanation:

The correct option is: Option B

Python loop

Which keyword is used to start a loop that iterates over a sequence in Python?

for
loop
iterate

Explanation:

The correct option is: Option A

Python while loop

Which keyword is used to start a loop that continues as long as a condition is true in Python?

loop
for
while

Explanation:

The correct option is: Option B

Python break statement

Which keyword is used to exit a loop prematurely in Python?

break
stop
exit

Explanation:

The correct option is: Option C

Python continue statement

Which keyword is used to skip the current iteration of a loop and continue with the next?

skip
next
continue

Explanation:

The correct option is: Option B

Python dictionary

Which of the following is the correct way to define a dictionary in Python?

mydict = {"a":1, "b":2}
mydict = ["a":1, "b":2]
mydict = ("a":1, "b":2)

Explanation:

The correct option is: Option A

Python set

Which of the following creates a set in Python?

s = []
s = set([1,2,3])
s = {}

Explanation:

The correct option is: Option C

Python input function

Which function is used to take input from the user in Python?

input()
scan()
get()

Explanation:

The correct option is: Option A

Python type casting

Which of the following converts a string to an integer in Python?

int()
float()
str()

Explanation:

The correct option is: Option B

Python len function

Which function returns the number of items in a list in Python?

len()
size()
count()

Explanation:

The correct option is: Option C

Python exception handling

Which keyword is used for exception handling in Python?

exception
try
catch

Explanation:

The correct option is: Option A