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.
What is the result of the program?
❌ 4
✅ 5
❌ 6
❌ Error will occur
❌ None of the mentioned
Explanation:
The task of append() method is to append a passed obj into an existing list. But instead of passing a list to the append method will not merge the two lists, the entire list which is passed is added as an element of the list ([1, 2, 3, 4, [5, 6]])
So the output is 5.
❌ 4
✅ 5
❌ 6
❌ Error will occur
❌ None of the mentioned
Explanation:
The task of append() method is to append a passed obj into an existing list. But instead of passing a list to the append method will not merge the two lists, the entire list which is passed is added as an element of the list ([1, 2, 3, 4, [5, 6]])
So the output is 5.
What is the result of the program?
❌ Runs normally, doesn’t display anything
❌ Displays 0, which is the automatic default value
✅ Error as one argument is required while creating the object
❌ Error as display function requires additional argument
❌ None of the mentioned
Explanation:
Since, the init special method has another argument a other than self, during object creation, one argument is required. For example: obj=test(“Hello”)
❌ Runs normally, doesn’t display anything
❌ Displays 0, which is the automatic default value
✅ Error as one argument is required while creating the object
❌ Error as display function requires additional argument
❌ None of the mentioned
Explanation:
Since, the init special method has another argument a other than self, during object creation, one argument is required. For example: obj=test(“Hello”)
What is the output of the program?
❌ Woof!
❌ Arff!
✅ *walking*
❌ AttributeError: 'JackRussellTerrier' object has no attribute 'walk'
❌ None of the mentioned
Explanation:
While bobo is an instance of JackRussellTerrier it still has a .walk() method. This method was inherited from the parent Dog class.
❌ Woof!
❌ Arff!
✅ *walking*
❌ AttributeError: 'JackRussellTerrier' object has no attribute 'walk'
❌ None of the mentioned
Explanation:
While bobo is an instance of JackRussellTerrier it still has a .walk() method. This method was inherited from the parent Dog class.
What is the output of the program?
❌ [1, 2, 3, 4, 5]
❌ [1, 2, 3, 4, 5, 6]
❌ [2, 3, 4, 5]
✅ [2, 3, 4, 5, 6]
❌ Error will occur
❌ None of the mentioned
Explanation:
The code line “second = first ” creates the shallow copy of the list. It means there will be a single list in memory. The first and second variables are pointed to the same list.
It does not maintain two separate lists, but only one. If you modify using one list variable, it will make the changes in the list for both variables.
If you want to maintain two separate lists for two list objects, you need to create a deep copy of the list.
❌ [1, 2, 3, 4, 5]
❌ [1, 2, 3, 4, 5, 6]
❌ [2, 3, 4, 5]
✅ [2, 3, 4, 5, 6]
❌ Error will occur
❌ None of the mentioned
Explanation:
The code line “second = first ” creates the shallow copy of the list. It means there will be a single list in memory. The first and second variables are pointed to the same list.
It does not maintain two separate lists, but only one. If you modify using one list variable, it will make the changes in the list for both variables.
If you want to maintain two separate lists for two list objects, you need to create a deep copy of the list.