What is the result of the code?
❌ 3
❌ 4
✅ 5
❌ Does not compile
❌ None of mentioned
Explanation:
In Python, everything is a reference, and references are passed by value. Parameter passing in Python is the same as reference passing in Java. As a consequence, the function can modify the value referred by passed argument, i.e. the value of the variable in the caller’s scope can be changed. Here the task of the function “addToList” is to add an element 10 in the list, So this will increase the length of the list by 1. So the output of the program is 5.
❌ 3
❌ 4
✅ 5
❌ Does not compile
❌ None of mentioned
Explanation:
In Python, everything is a reference, and references are passed by value. Parameter passing in Python is the same as reference passing in Java. As a consequence, the function can modify the value referred by passed argument, i.e. the value of the variable in the caller’s scope can be changed. Here the task of the function “addToList” is to add an element 10 in the list, So this will increase the length of the list by 1. So the output of the program is 5.
What is the result of the code?
✅ 111
❌ 555
❌ 666
❌ Code does not compile
❌ Runtime error
❌ None of the above
Explanation:
Instantiation of the class “Acc” automatically calls the method init and passes the object as the self parameter. 111 is assigned to data attribute of the object called id.
The value “555” is not retained in the object as it is not assigned to a data attribute of the class/object. So, the output of the program is “111”
✅ 111
❌ 555
❌ 666
❌ Code does not compile
❌ Runtime error
❌ None of the above
Explanation:
Instantiation of the class “Acc” automatically calls the method init and passes the object as the self parameter. 111 is assigned to data attribute of the object called id.
The value “555” is not retained in the object as it is not assigned to a data attribute of the class/object. So, the output of the program is “111”
What is the output of the program?
❌ 0 2 3 10
❌ 32 34 35 42
✅ 48 64 72 128
❌ 48 144 192 480
❌ Code does not compile
❌ None of the mentioned
Explanation:
An Empty Tuple has 48 Bytes as Overhead size and each additional element requires 8 Bytes.
(1, 2) Size: 48 + 2 * 8 = 64
(1, 3, (4, 5)) Size: 48 + 3 * 8 = 72
(1, 2, 3, 4, 5, [3, 4], ‘p’, ‘8’, 9.777, (1, 3)) Size: 48 + 10 * 8 = 128
❌ 0 2 3 10
❌ 32 34 35 42
✅ 48 64 72 128
❌ 48 144 192 480
❌ Code does not compile
❌ None of the mentioned
Explanation:
An Empty Tuple has 48 Bytes as Overhead size and each additional element requires 8 Bytes.
(1, 2) Size: 48 + 2 * 8 = 64
(1, 3, (4, 5)) Size: 48 + 3 * 8 = 72
(1, 2, 3, 4, 5, [3, 4], ‘p’, ‘8’, 9.777, (1, 3)) Size: 48 + 10 * 8 = 128
What will be the output of the code?
❌ 0 1 2 0
✅ 0 1 2
❌ Does not compile
❌ Runtime error
❌ None of the mentioned
Explanation:
The correct answer to the question is option 0 1 2. Because there is a break control statement, in the script, so else statement won’t be executed.
❌ 0 1 2 0
✅ 0 1 2
❌ Does not compile
❌ Runtime error
❌ None of the mentioned
Explanation:
The correct answer to the question is option 0 1 2. Because there is a break control statement, in the script, so else statement won’t be executed.
What is the output of the code?
✅ Hello WorldWorldWorldWorldWorld
❌ Hello World 5
❌ Hello World,World,World,World,World
❌ Hello HelloHelloHelloHelloHello
❌ A runtime exception is thrown
❌ None of the mentioned
Explanation:
For some functions, you may want to make some parameters optional and use default values in case the user does not want to provide values for them. This is done with the help of default argument values. You can specify default argument values for parameters by appending to the parameter name in the function definition the assignment operator (=) followed by the default value.
The function named say is used to print a string as many times as specified. If we don’t supply a value, then by default, the string is printed just once. We achieve this by specifying a default argument value of 1 to the parameter times.
In the first usage of say, we supply only the string and it prints the string once. In the second usage of say, we supply both the string and an argument 5 stating that we want to say the string message 5 times.
✅ Hello WorldWorldWorldWorldWorld
❌ Hello World 5
❌ Hello World,World,World,World,World
❌ Hello HelloHelloHelloHelloHello
❌ A runtime exception is thrown
❌ None of the mentioned
Explanation:
For some functions, you may want to make some parameters optional and use default values in case the user does not want to provide values for them. This is done with the help of default argument values. You can specify default argument values for parameters by appending to the parameter name in the function definition the assignment operator (=) followed by the default value.
The function named say is used to print a string as many times as specified. If we don’t supply a value, then by default, the string is printed just once. We achieve this by specifying a default argument value of 1 to the parameter times.
In the first usage of say, we supply only the string and it prints the string once. In the second usage of say, we supply both the string and an argument 5 stating that we want to say the string message 5 times.
What is the result of the program?
❌ 4
✅ 28
❌ 30
❌ Compiler error
❌ None of the above
Explanation:
In python, range() is a built-in function, which is used to return a sequence of numbers given between the starting and ending argument of the function. We can also control the amount of steps it should take in a particular direction.
As in the above code, the first and second argument we provided is 10 and 2. So, we have to take the sequence of numbers between 10 to 2. In the third argument, we have provided -2, which means we have to decrement 2 from the first argument(10) till it reaches the second argument(2).
❌ 4
✅ 28
❌ 30
❌ Compiler error
❌ None of the above
Explanation:
In python, range() is a built-in function, which is used to return a sequence of numbers given between the starting and ending argument of the function. We can also control the amount of steps it should take in a particular direction.
As in the above code, the first and second argument we provided is 10 and 2. So, we have to take the sequence of numbers between 10 to 2. In the third argument, we have provided -2, which means we have to decrement 2 from the first argument(10) till it reaches the second argument(2).
What is the result of the program?
❌ 5 5
❌ -5 5
✅ 5 -5
❌ -5 -5
❌ Error
❌ None of the mentioned
Explanation:
The slice expression on the right side of the assignment reverses the tuple. (y, x)[::-1] = (5, -5).
The assignment is thus equivalent to this compound tuple packing/unpacking assignment: x, y = (5, -5).
x and y retain the values they had originally.
❌ 5 5
❌ -5 5
✅ 5 -5
❌ -5 -5
❌ Error
❌ None of the mentioned
Explanation:
The slice expression on the right side of the assignment reverses the tuple. (y, x)[::-1] = (5, -5).
The assignment is thus equivalent to this compound tuple packing/unpacking assignment: x, y = (5, -5).
x and y retain the values they had originally.