mediumPythoninterning
What will this code print?
a = 256
b = 256
c = 257
d = 257
print(a is b, c is d)Read the full question →Medium questions combine two ideas: scope plus timing, types plus inference, a method plus the edge case it does not handle.
This is where most real screening rounds sit. If you are preparing for an interview next week, start here.
Expect snippets where the obvious answer is wrong for a reason you can name once you see it.
Eighteen real medium questions from across the library, code snippet included. The answer options and explanations come after you attempt them.
a = 256
b = 256
c = 257
d = 257
print(a is b, c is d)Read the full question →def deco(f):
def wrapper():
return "Decorated " + f()
return wrapper
@deco
def say():
return "Hello"
print(say())Read the full question →print(any([]), all([]))Read the full question →parseInt("5px")Read the full question →class A:
def hello(self):
return "A"
class B(A):
def hello(self):
return super().hello() + "B"
print(B().hello())Read the full question →class A:
val = []
a1 = A()
a2 = A()
a1.val.append(1)
print(a2.val)Read the full question →a = [1, 2, 3]
b = [1, 2, 3]
print(a == b, a is b)Read the full question →for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 100);
}Read the full question →<ul>\n <li>Item 1</li>\n <li>Item 2\n <ul>\n <li>Subitem</li>\n </ul>\n </li>\n</ul>Read the full question →x = [[0]] * 3
x[0][0] = 99
print(x)Read the full question →for (let i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 100);
}Read the full question →print([] or "Hello")
print("" and "World")Read the full question →Number.isNaN("test")Read the full question →let fruits = ["apple", "banana", "orange"];
let result = fruits.slice(1);
console.log(result);Read the full question →def func(a, b=[]):
b.append(a)
return b
print(func(1))
print(func(2))Read the full question →async function test() {
return "Hello";
}
console.log(test());Read the full question →<table>\n <thead>\n <tr><th>Header</th></tr>\n </thead>\n <tbody>\n <tr><td>Data</td></tr>\n </tbody>\n</table>Read the full question →// this has nothing to do with question, it's a test question
const Abc = () => {
const [a, v] = useState("abc");
return (
<div>
new abc
dkkdkd
<span>
Nice working
</span>
</div>
)
}Read the full question →