Python

Python

Tuples has 9 Questions

Which of the following is a Python tuple?

[1, 2, 3]
(1, 2, 3)
{1, 2, 3}
{}
Suppose t = (1, 2, 4, 3), which of the following is incorrect?

print(t[3])
t[3] = 45
print(max(t))
print(len(t))
What will be the output?
  1. >>>t=(1,2,4,3)
  2. >>>t[1:3]

(1, 2)
(1, 2, 4)
(2, 4)
(2, 4, 3)
What will be the output?
  1. >>>t=(1,2,4,3)
  2. >>>t[1:-1]

(1, 2)
(1, 2, 4)
(2, 4)
(2, 4, 3)
What will be the output?
  1. d = {"john":40, "peter":45}
  2. d["john"]

40
45
"john"?
"peter"?
What will be the output?
  1. >>>t = (1, 2)
  2. >>>2 * t

(1, 2, 1, 2)
[1, 2, 1, 2]
(1, 1, 2, 2)
[1, 1, 2, 2]
What will be the output?
  1. >>>my_tuple = (1, 2, 3, 4)
  2. >>>my_tuple.append( (5, 6, 7) )
  3. >>>print len(my_tuple)

1
2
5
Error
What will be the output?
  1. numberGames = {}
  2. numberGames[(1,2,4)] = 8
  3. numberGames[(4,2,1)] = 10
  4. numberGames[(1,2)] = 12
  5. ?
  6. sum = 0
  7. for k in numberGames:
  8.     sum += numberGames[k]
  9. ?
  10. print len(numberGames) + sum

30
24
33
12
What will be the output?
  1. numberGames = {}
  2. numberGames[(1,2,4)] = 8
  3. numberGames[(4,2,1)] = 10
  4. numberGames[(1,2)] = 12
  5. ?
  6. sum = 0
  7. for k in numberGames:
  8.     sum += numberGames[k]
  9. ?
  10. print len(numberGames) + sum

30
24
33
12