Q. 1

What is the output of the following ?

pe = "python easy"
print(pe[5])

Options:

Explanation

Correct answer is : A

print(pe[5]) will print 5 th index which is "n"

Discuss It

Q. 2

What is the output of the following ?

pe = "python easy"
print(pe[2:5])

Options:

Explanation

Correct answer is : B

pe[2:5] will slice characters from position 2 (included) to 5 (excluded)

Discuss It

Q. 3

What is the output of the following code ?

p = [[1, 2, 3],               
 [4, 5, 6],
 [7, 8, 9]]

print(p[1][2])

 

Options:

Explanation

Correct answer is : B

p[1] will give you [4. 5. 6]

[4. 5. 6] of index 2 i.e. [4. 5. 6][2] will result in 6

Discuss It

Q. 4

What is the output of the following code ?

>>> list('python')

 

Options:

Explanation

Correct answer is : C

When a string converted to list using list() function, wach character is converted to one element of a list 

Discuss It

Q. 5

What is the output of the following code ?

>>> s = ['python', 'is', 'easy', 'programming', 'language']
>>> s[:-1]

 

Options:

Explanation

Correct answer is : A

It is provide a list slice upto last but one element that it "programming"

Refer to https://www.pythoneasy.com/python-programming-tutorial/python-list#5

Discuss It

Q. 6

What is the output of the following code ?

>>> s = ['python', 'is', 'easy', 'programming', 'language']
>>> s[:-1][-1]

Options:

Explanation

Correct answer is : D

s[:-1] will give us ['python', 'is', 'easy', 'programming'].

Hence [-1] index of ['python', 'is', 'easy', 'programming'], will be 'programming'

Discuss It

Q. 7

What is the output of the following code ?

>>> s = [1, 2, 3]
>>> s*3

 

Options:

Explanation

Correct answer is : C

The * operator multiplies the list and creates a new list 

Discuss It

Q. 8

What is the output of the following code ?

>>> s1 = [23, 24, 25, 12]
>>> s2 = [23, 24, 26]
>>> s1 > s2

 

Options:

Explanation

Correct answer is : A

The comparison operator ">" compares each element until it finds a difference . When 25  of s1 is compared with 26 of s2, > gives False and does not move further to test.

So the result will be False

Discuss It

Q. 9

What is the output of the following code ?

s1 = [23, 45, 61, 12, 31, 91, 23]

for i in range(1, 7):
    s1[i - 1] = s1[i]

for i in range(0, 7):
    print(s1[i], end=" ")

 

Options:

Explanation

Correct answer is : B

s1[i - 1] = s1[i] will shift each element to left

For example in the first iteration , s[0] = s1[1],  the value in s1[1] will be assigned to s1[0].

So the result will be 45 61 12 31 91 23 23

Discuss It

Q. 10

What is the output of the following code ?

s = [56, 7, 89, 24, 72, 91, 49]
if 72 in s:
    print(True)
else:
    print(False)

 

Options:

Explanation

Correct answer is : A

The "in" operator checks the element available in the list, If yes then it returns True.

As 72 is available is s, it will print True

Discuss It
Submit Your Answers

Interview Questions

on
Data Types

Tutorial

on
Data Types

Programs

on
Data Types
Click any Link
to navigate to certain page easily
Write a line to us
Your Email
Title
Description