Assertion Reasoning Questions- Python
Assertion Reasoning Questions- Python
22. Assertion (A): ('a' and 'b' or not 5) is a valid expression in Python.
Reasoning (R): In Python, strings and numbers can be treated as Boolean values.
23. Assertion (A): eval('3.3')*3 is a valid expression in Python .
Reasoning (R): * works as replication operator between a string and an integer.
24. Assertion (A): If L is a list, then L+=range(5) is an invalid statement.
Reason (R): Only a list can be concatenated to a list.
25. Assertion (A): We cannot delete an element from a tuple.
Reasoning (R): tuples are immutable data objects.
26. Assertion (A): A tuple can be concatenated to a list, but a list cannot be concatenated to a tuple.
Reason (R): Lists are mutable and tuples are immutable in Python.
27. Assertion (A): 'Amitabh' > 'Ajit'
Reasoning: Strings of bigger length are greater than strings of smaller length
28. Assertion (A): 'Amitabh' > 'Ajit'
Reasoning: Unicode/ASCII value of 'm' is greater than that of 'j'.
29. s="Alpha"+"Beta"
Assertion (A): Value of s will be "AlphaBeta".
Reasoning (R): Operator '+' adds the operands, if both are numbers & concatenates the operands if both are
strings.
30. Assertion (A): In Python, elements of a string can be accessed using index numbers.
Reasoning (R): Strings are sequences in Python.
31. Assertion (A): Elements of a sequence can always be accessed using index numbers.
Reasoning (R): All iterables are sequences in Python.
32. Assertion (A): All iterables are sequences in Python.
Reasoning (R): Elements of a sequence can be accessed using index numbers.
33. Assertion (A): The number of actual parameters in a function call may not be equal to the number of formal
parameters of the function.
Reasoning (R): During a function call, it is optional to pass the values to default parameters.
34. Assertion (A): [1,2,3] is an invalid key for a dictionary in Python.
Reason (R): Only numbers and strings can be the keys of a dictionary in Python.
35. Assertion (A): 2 in {'a':1, 'b':2, 'c':3} is True
Reasoning (B): 2 is value in the dictionary.
36. Assertion (A): 2 in {'a':1, 'b':2, 'c':3} is False
Reasoning (B): 2 is a key present in the dictionary.
37. Assertion (A): 2 in {'a':1, 'b':2, 'c':3} is False
Reasoning (B): 2 is a value present in the dictionary.
38. Assertion (A): 2 in {'a':1, 'b':2, 'c':3} is False
Reasoning (B): 2 is not a key in the dictionary.
39. Assertion (A) : Keys in a Python dictionary should be unique.
Reasoning (R) : Only immutable data types can be used as keys.
40. Assertion (A): print(f1()) is a valid statement even if the function f1() has no return statement.
Reasoning (R): A function always returns a value even if it has no return statement.
41. Assertion (A): A variable declared as global inside a function is visible outside the function only after the
function is called.
Reasoning (R): All variables declared outside are not visible inside a function till they are redeclared with global
keyword.
42. Assertion (A): If the arguments in a function call statement match the number and order of arguments as defined
in the function definition, such arguments are called positional arguments.
Reasoning (R): During a function call, the argument list first contains keyword argument(s) followed by
positional argument(s).
43. Assertion (A): In Python, the statement return [<expression>] exits a function.
Reasoning (R): return statement transfers the control to the caller. A return statement with no arguments is the
same as return None.
44. Assertion (A):- keyword arguments are related to the function calls.
Reasoning (R):- when you use keyword arguments in a function call, the caller identifies the arguments by
parameter name.
45. Assertion (A): The default value of an argument will be used inside a function if we do not pass a value to that
argument at the time of the function call.
Reasoning (R): the default arguments are optional during the function call.
46. Assertion (A): Built in functions are predefined in the language that are used directly.
Reasoning(R): print() and input() are built in functions in Python.
47. Assertion (A):- The default arguments can be skipped in the function call.
Reasoning (R):- The function argument will take the default values even if the values are supplied in the function
call.
48. Assertion (A): The function definition def calculate(a, b,c=1,d): will give error.
Reasoning (R): All the non-default arguments must precede the default arguments.
49. Assertion (A): A function in Python always returns a value.
Reasoning (R): return statement is optional in Python.
50. Assertion (A): We cannot redefine an inbuilt function in Python.
Reasoning (R): Keywords cannot be redefined in Python.
51. Assertion (A): If a text file already containing some text is opened in write mode the previous contents are
overwritten.
Reasoning (R): When a file is opened in write mode the file pointer is present at the beginning position of the
file.
52. Assertion (A): If a text file is opened in 'a+' mode, then we can write the data anywhere in the file.
Reasoning (R): seek() method can be used to place the pointer anywhere in a file.
53. Assertion (A): seek() method can be used instead of tell() method.
Reasoning (R): seek(0) returns the value of file pointer without changing it.
54. Assertion (A): We can use any string, instead of a comma, as a delimiter of a csv file.
Reasoning (R): Comma is the default delimiter of a csv file.
55. Assertion (A): CSV (Comma Separated Values) is a file format for data storage which looks like a text file.
Reasoning (R): In a CSV file the information is organized with one record on each line and each field is separated
by semi-colon.
56. Assertion (A): CSV module allows to write a single record in each row in a CSV file using the writerow()
function.
Reasoning (R): writerow() function creates header row in csv file by default.
57. Assertion (A): CSV stands for Comma Separated Values.
Reasoning (R): CSV files are a common file format for transferring and storing data.
58. Assertion (A): Pickling is the process by which a Python object is converted to a byte stream.
Reasoning (R): load() method is used to write the objects in a binary file. dump() method is used to read
data from a binary file.
59. Assertion (A): If only strings are written to a binary file, then it can be treated as a text file.
Reasoning (R): Pickling and unpickling can be done for strings also.
60. Assertion (A): A binary file in python can be used to store any kind of objects that can be later retrieved in their
original form using pickle module.
Reasoning (R): Binary files are just like normal text files and can be read using a text editor like notepad.