Q1: What will be the output of the following code?
print('Career')
print('Labs')
Answer: Career Labs(in next line)
Explanation: "Career" and "Labs" are printed in separate lines because by default
Explanation: "Career" and "Labs" are printed in separate lines because by default
print() ends with a new line.
Q2: What will be the output of the following code?
print('Hello')
print('World')
Answer: Hello (newline) World
Explanation: By default,
Explanation: By default,
print() adds a new line after each call.
Q3: What will be the output of the code?
a = 10
b = 20
multiple = a * b
print('multiple')
Answer: multiple
Explanation: Anything in quotes is treated as a string, so it prints 'multiple'.
Explanation: Anything in quotes is treated as a string, so it prints 'multiple'.
Q4: What will be the output if inputs are "abc" and "def"?
a = int(input())
b = int(input())
c = a + b
print('c')
Answer: Value Error
Explanation:
Explanation:
int() expects integers. Strings give ValueError.
Q5: What will be the output if inputs are 40 and 57 (typecast int)?
a = int(input())
b = int(input())
c = a + b
print('c')
Answer: 97
Explanation: Integers are added numerically.
Explanation: Integers are added numerically.
Q6: What will be the output if inputs are 40 and 57 (without typecast)?
a = input()
b = input()
c = a + b
print('c')
Answer: 4057
Explanation:
Explanation:
input() returns strings. Concatenation gives '4057'.
Q7: What is the output of print(17/10)?
Answer: 1.7
Explanation: '/' performs floating-point division.
Explanation: '/' performs floating-point division.
Q8: What is the output of print(17//10)?
Answer: 1
Explanation: '//' is floor division.
Explanation: '//' is floor division.
Q9: Will id1 and id2 have the same value?
a = 10 id1 = id(a) b = a + 2 - 2 id2 = id(b)
Answer: Yes
Explanation: Integers with the same value share the same memory id in Python.
Explanation: Integers with the same value share the same memory id in Python.
Q10: What is the type of x after execution?
x = 'abcd' x = 10
Answer: int
Explanation: Variables take the type of the last assigned value.
Explanation: Variables take the type of the last assigned value.
Tags:
Quiz
