What will be the output of the following Python function?
hex(15)
f
0xF
0Xf
0xf
ord()
ord(‘ ‘)
ord(”)
ord(“”)
len(["hello",2, 4, 6])
4
3
Error
6
set
list
tuple
string
number of arguments
number of arguments + 1
number of arguments – 1
none of the mentioned
What will be the output of the following Python code?
def foo(k): k[0] = 1 q = [0] foo(q) print(q)
[0]
[1]
[1, 0]
[0, 1]
one-star followed by a valid identifier
one underscore followed by a valid identifier
two stars followed by a valid identifier
two underscores followed by a valid identifier
zero
one
zero or more
one or more
def foo(fname, val): print(fname(val)) foo(max, [1, 2, 3]) foo(min, [1, 2, 3])
3 1
1 3
error
def foo(): return total + 1 total = 0 print(foo())
0
1
def foo(): total += 1 return total total = 0 print(foo())
def foo(x): x = ['def', 'abc'] return id(x) q = ['abc', 'def'] print(id(q) == foo(q))
True
False
None
def foo(i, x=[]): x.append(i) return x for i in range(3): print(foo(i))
[0] [1] [2]
[0] [0, 1] [0, 1, 2]
[1] [2] [3]
[1] [1, 2] [1, 2, 3]
def foo(k): k = [1] q = [0] foo(q) print(q)
one star followed by a valid identifier
getopt
os
getarg
main
null
you cannot access it
the program’s name
the first argument
identifier followed by an equal to sign and the default value
identifier followed by the default value within backticks (“)
identifier followed by the default value within square brackets ([])
identifier