Tag Archives: python code quiz

Python Quiz-10

Q1. What will be the output of the following code:

  1. 8
  2. 9
  3. 10
  4. Error!

Answer: 2
Explanation: In Python language, len() function gives the length of an object. When the object is a string, it will output the number characters in the string.

Q2. What will be the output of following code:

  1. 5
  2. 6
  3. 5.14
  4. 7

Answer: 2
Explanation: => print(func3(2))
=> return math.ceil(func1(2)+func2(2))
=> return math.ceil(2*2+math.sqrt(2))
=> return math.ceil(4+1.414)
=> return math.ceil(5.414)
=> return 6
=> 6

Q3. What will be the output of following code:

  1. {‘a’: 1, ‘b’: 2, ‘c’: 3}
  2. {‘c’: 3}
  3. {‘a’: 1, ‘b’: 2}
  4. TypeError

Answer: 4
Explanation: D.popitem() -> (k, v), remove and return some (key, value) pair as a 2-tuple. But in this question only one argument is given to popitem() method.

Q4. Which of the following statements is not true?

  1. We can change the value of a private variable of superclass in the subclass
  2. Superclass non-private method can be overridden.
  3. The constructor of a class in invoked automatically.
  4. A derived class is a subclass of superclass

Answer: 1
Explanation: We can not change the value of a private variable of superclass in the subclass.

Q5. What type of error will be raised when the imported module is not found?

  1. ImportError
  2. NullPointerError
  3. NameError
  4. IndexNotFoundError

Answer: 1
Explanation: ImportError will be raised when the imported module is not found.

Q6. How does Python treat a string literal when it is not assigned to any variable?

  1. It will ignore the string literal.
  2. It will automatically assings a variable to it.
  3. It will through an error.
  4. None of the above.

Answer: 1
Explanation: In Python language, if you do not assign a string literal to a variable, it will ignore the string literal while in other languages like Java it will throw a compile time error.

Q7. In Python, which of the following variable is not of a integer data type?

  1. x = 435757438
  2. x = 5
  3. x = 23.45
  4. x = -5

Answer: 3
Explanation: Int is a whole number, it can be either positive or negative. It can not have decimal values also it can be of unlimited length.

Q8. Which of the following statement will extract the percentage of the mentioned student?

  1. print(data[‘school’][‘student’][‘result’][‘percentage’])
  2. print(data[‘School’][‘student’][‘result’][‘percentage’])
  3. print(data[‘School’][‘student’][‘result’][0])
  4. print(data[‘Sschool’][‘student’][0][‘percentage’])

Answer: 2
Explanation: json.loads() method can be used to parse a valid JSON string and convert it into a Python Dictionary.
json.loads() in Python
=> print(data[‘School’][‘student’][‘result’][‘percentage’])
=> 70%

Python Quiz-9

Q1. Which of the following statements is true?

  1. Special method __add()__ is called when + operator is used.
  2. In Python, same operator may behave differently depending upon operands.
  3. __init__() function is called when a new object is instantiated.
  4. All of the above

Answer: 4
Explanation: All of the given three options are correct.

Q2. In Python, which of the following statement will print a random number between 1 and 10 (both 1 and 10 included)?

  1. print(random.randrange(1, 10))
  2. print(random.random(1, 10))
  3. print(random.randint(1, 10))
  4. None of the above.

Answer: 3
Explanation: 1. print(random.randrange(1, 10)) -> This will print a random integer between 1 and 10 where 10 is not included.
2. print(random.random(1, 10)) -> This will throw an error because random does not take any argument but two are given.
3. print(random.randint(1, 10)) -> This will print a random number between 1 and 10 (both 1 and 10 included).

Q3. Which of the following is not true of global variable in Python?

  1. global keyword can be used to create a global variable inside a local scope.
  2. Accessible only in the block they are defined in.
  3. A variable created in the main body of the Python code is a global variable.
  4. Accessible from anywhere in the script.

Answer: 2
Explanation: Global variables are available from within any scope, either it is global or local.

Q4. If x = 2**4/2+3-1, then what will be the data type of x?

  1. int
  2. float

Answer: 2
Explanation: Division operator is used in x = 2**4/2+3-1 and division operator gives the value including the decimals which will be of float data type.

Q5. Which of the following method can be used to combine strings and numbers?

  1. concatenate()
  2. join()
  3. append()
  4. format()

Answer: 4
Explanation: The format() method format the passed arguments and places them in the string according to the placeholders {}.
Fancier Output Formatting

Q6. Suppose x = 6.3, then which of the following statement will throw an error?

  1. y = float(x)
  2. y = int(x)
  3. y = complex(x)
  4. None of the above.

Answer: 4
Explanation: int, float and complex are numeric data types. These will cast ‘x’ into it’s respective data types.

Q7. What will be the output of print(ord(‘the’))?

  1. 116 104 101
  2. 116 116 116
  3. 104 104 104
  4. TypeError

Answer: 4
Explanation: Python ord() function returns the Unicode code from a given character. This function accepts a string of unit length as an argument and returns the Unicode equivalence of the passed argument.
Reference: ord() function in Python

Q8. In Python, which of the following character is used to add at the start of a line to make it a comment?

  1. #
  2. //
  3. &

Answer: 1
Explanation: In Python language comments start with # and the rest of the line will be rendered as comment.

Python Quiz-8

Q1. What will be the output of following code:

  1. [7, 9, 2, 0, 2, 1]
  2. [‘7’, ‘9’, ‘2’, ‘0’, ‘2’, ‘1’]
  3. [7, 2, 0, 2, 1]
  4. Runtime error!

Answer: 2
Explanation: This is an example of list comprehension in Python. List comprehensions are used for creating new lists from other iterables like tuples, strings, arrays, lists, etc. A list comprehension consists of brackets containing the expression, which is executed for each element along with the for loop to iterate over each element.
List Comprehensions

Q2. What are the name of the operators |, &, >> and << respectively?

  1. AND, OR, RIGHT SHIFT and LEFT SHIFT
  2. AND, OR, LEFT SHIFT and RIGHT SHIFT
  3. OR, AND, LEFT SHIFT and RIGHT SHIFT
  4. OR, AND, RIGHT SHIFT and LEFT SHIFT

Answer: 4
Explanation: OR, AND, RIGHT SHIFT and LEFT SHIFT are name of the |, &, >> and << operators respectively.

Q3. What will be the output of following code:/code/

  1. [1, 2] [1, 2, 3, 4]
  2. [1, 2, 3, 4] [1, 2, 3, 4]
  3. [1, 2, 3, 4] [1, 2]
  4. [1, 2] [3, 4]

Answer: 2
Explanation: In Python language, assigning one variable to another variable creates an alias of each variable. Here variable b is an alias of variable a. It means both variable a and b points to the same object in the memory. That’s why when you are updating the value of variable b, value of variable a is also changing.

Q4. Python is an object oriented programming language.

  1. True
  2. False

Answer: 1
Explanation: Python is an object oriented programming language. Almost everything in Python is an object. A class in Python is a blueprint for creating objects.

Q5. What will be the output of following code:

  1. 1 2 (3, 4, 5)
  2. 1 2 3
  3. 1 2 [3, 4, 5]
  4. ValueError

Answer: 3
Explanation: *variable is basically extended iterable unpacking. It will assign a list of all items not assigned to a regular variable name. So from tuple “num”, 1 is assinged to a, 2 is assigned to b and rest all items will be assigend as list to c.
Extended Iterable Unpacking

Q6. Which of the following statement is the correct way of assigning an integer value to a variable in Python?

  1. x = ‘6’
  2. int x = 6;
  3. x = 6
  4. Integer x = 6;

Answer: 3
Explanation: x = ‘6’ -> will create a string data type.
int x = 6; and Integer x = 6; -> It is a way of assignment and declaration in Java language.

In Python there is no need to declare the data type using int or Integer. It will create a variable with respect to the type of data you assing to it.

Q7. What is the syntax for multiline comment in Python?

  1. Use /* at the start of the first line and use */ at the end of the last line.
  2. Use <-- at the start of the first line and use --> at the end of the last line.
  3. Python does not have syntax for multiline comment. You can either use # at the start of every line or make it as multiline string (triple quote).
  4. None of the above.

Answer: 3
Explanation: Since Python does not have syntax for multiline comments, there is a workaround. As Python ignores the string literal if it is not assigned to a variable, we can add multiline string in our code and place the multiline comment inside it.

Q8. What will be the output of following code:

  1. 1 2 3
  2. 1 2 3 4
  3. 1 2 3 5
  4. 1 2 3 4 5

Answer: 1
Explanation: while loop executes the block until a condition is satisfied. When the condition becomes false, the statement immediately after the loop is executed. The else clause is only executed when your while condition becomes false. If you break out of the loop, or if an exception is raised, it won’t be executed.
Reference: While Loop

Python Quiz-7

Q1. if x = [1, 2, 5, 3, 4], what will be the output of print(x[0:3:2])?

  1. [1, 5, 4]
  2. [1, 5]
  3. [1, 2, 5, 3, 4]
  4. List index out of range exception!

Answer: 2
Explanation: Slice in Python list here refer to list[::]. So x[0:3:2] will start at index 0, stop at index 3 at take a step of 2.

Q2. What is the difference between a method and a function in Python?

  1. Functions can be called only by its name but methods can not be called by its name only.
  2. we don’t need a class to define a function but methods are defined inside a class.
  3. Functions are independent entities in a program while methods are dependent on the class they belong to.
  4. All of the above.

Answer: 4
Explanation: All the given three options are correct.

Q3. What will be the output of following code:

  1. [20, 30, 40, 50]
  2. [10, 20, 30, 40, 10]

Answer: 2
Explanation: In Python language, + operator append the elements to the original array.

Q4. What will be the output of following code:

  1. 3 2
  2. 2 2
  3. 2 3
  4. SyntaxError

Answer: 4
Explanation: It will raise an error. In function definition, non-default arguments should be written before the default arguments.

Q5. Which of the following is true when you open a file using with keyword?

  1. File reading and writing are faster using the with statement.
  2. The file is automatically closed after leaving the block, and all the resources that are tied up with the file are released.
  3. You need not to handle exception anymore in the whole script.

Answer: 2
Explanation: When you open a file using with keyword, the file is automatically closed after leaving the block, and all the resources that are tied up with the file are released.

Q6. A class can serve as base class for many derived classes.

  1. True
  2. False

Answer: 1
Explanation: yes a class can serve as base class for many derived classes. It is also call as Hierarchical inheritance.

Q7. The following code will throw an error.

  1. True
  2. False

Answer: 1
Explanation: **kwargs are used as arbitrary keyword arguments. If we do not know how many keyword arguments that will be passed into our function then we can add two asterisk ** before the parameter name in the function definition. In the given function definition x will be a dictinary of arguments. That’s why print(x[a]) will raise an error.

Q8. Which of the following statement will create a variable of string type?

  1. a = ”’AILearner”’
  2. a = “AILearner”
  3. a = ‘AILearner’
  4. All of the above.

Answer: 4
Explanation: In Python language, a string can be created by using any of the single, double or triple quotation marks. Usually three quotes are used to create a multiline string.

Python Quiz-6

Q1. In Python, which of the following is the super class of all created classes?

  1. Super class
  2. Object class
  3. Integer class
  4. Base class

Answer: 2
Explanation: Object class is the super class of all created classes.

Q2. What will be the output of following code:

  1. [1, 2] [1, 2, 3]
  2. [1, 2, 3] [1, 2]
  3. [1, 2, 3] [1, 2, 3]
  4. [1, 2] [1, 2]

Answer: 4
Explanation: pop(index) method remove the item of a list at specified index. If index is not specified it will remove the first element of the list. Also as x is assigned to variable y and both refer to the same object in the memory, value of x and y will be same.

Q3. What will be the output of following code:

  1. 2
  2. 1
  3. 4
  4. 3

Answer: 1
Explanation: del x[1] => x = {2: ‘b’, 3: ‘c’}
x[1] = 5 => x = {2: ‘b’, 3: ‘c’, 1: 5}
del x[2] => x = {3: ‘c’, 1: 5}

Q4. What will be the output of following code:

  1. x y
  2. 1 2
  3. x y
  4. 1 2

Answer: 3
Explanation: **kwargs are used as arbitrary keyword arguments. If we do not know how many keyword arguments that will be passed into our function then we can add two asterisk ** before the parameter name in the function definition.
Arbitrary Keyword Arguments (**kwargs) make the way for the function to receive the dictionary of arguments.

Q5. In Python, which of the following is a numeric data type?

  1. int
  2. float
  3. complex
  4. All of the above.

Answer: 4
Explanation: In Python language, there are three types of numeric data.
1. int (Example : 0, 2, -1, etc.)
2.float (Example : 0.0, 2.3, -1.5, etc.)
3.complex(Example : 0j, 2j, -1.5j, etc.)

Q6. What will be the output of following code:

  1. {1, 2, 3} {1, 2, 3, 4}
  2. {1, 2, 3, 4} None
  3. {1, 2, 3, 4} {1, 2, 3, 4}
  4. Error

Answer: 2
Explanation: add() method does not return any value, that’s why x2 will be None.

Q7. What will be the output of following code”

  1. False 5
  2. True 5
  3. False 3
  4. True 3

Answer: 4
Explanation: When you open a file using with keyword, the file is automatically closed after leaving the block, and all the resources that are tied up with the file are released.

Q8. What is the difference between a global variable and a local variable?

  1. Global variable can be used inside a function only while local variable can be used both inside and outside the function.
  2. Local variable can be used inside a function only while global variable can be used both inside and outside the function.
  3. Both are same.
  4. Both are different name for same variables.

Answer: 2
Explanation: As stated, Local variable can be used inside a function only while global variable can be used both inside and outside the function.

Python Quiz-5

Q1. What will be the output of following code:

  1. 3
  2. 1
  3. 2
  4. Error

Answer: 3
Explanation: To build a class/object as an iterator, we need the methods __iter__() and __next__().
The __next__() method return the next item in the sequence.
myiter = iter(a) => Creates an iterator.
next(myiter) will execute the __next__() method of class A.
Python Iterators

Q2. The following code will throw an error.

  1. True
  2. False

Answer: 2
Explanation: *args are used as arbitrary Arguments. If we do not know how many arguments that will be passed into our function then we can add a * before the parameter name in the function definition.

Q3. What will be the output of following code:

  1. 8 5
  2. 8 6
  3. 7 6
  4. 7 5

Answer: 4
Explanation: strip() method removes any leading and trailing characters from a string.

Q4. What will be the output of following code:

  1. (‘AILearner’,’AILearner’,’AILearner’)
  2. AILearnerAILearnerAILearner
  3. (‘AILearner3’)
  4. Error

Answer: 2
Explanation: Here, * operator will multiply the content of string ‘AILearner’ 3 times.

Q5. What will be the output of following code:

  1. Python
  2. Java
  3. Java
    Python
  4. Python
    Java

Answer: 2
Explanation: Java is the correct answer.

Q6. What will be the output of following code:

  1. [1, 2, 3]
  2. [1, 3]
  3. [1, 2]
  4. Throws an error!

Answer: 1
Explanation: As the len(x) = 2, x[3:4] will add the data at the end of the list.
Extending a list in Python

Q7. Which of the following data types can have only two values (either True or False)?

  1. integer
  2. Strings
  3. Boolean
  4. Float

Answer: 3
Explanation: Booleans can only have one of two values: True of False.

Q8. What will be the output of print(2 * 3 ** 3 * 2)?

  1. 108
  2. 432
  3. 1458
  4. 36

Answer: 1
Explanation: ** is a power operator and it has higher precedence than * multiplication operator. So the equation will be solved as follows:
=> 2 * 3 ** 3 * 2
=> 2 * 27 * 2
=> 54 * 2
=> 108

Python Quiz-4

Q1. Which of the following statement will read entire content of a text file as string?

  1. txtfile = open(‘a.txt’, ‘r’)
    txtfile.read()
  2. txtfile = open(‘a.txt’, ‘r’)
    txtfile.readline()
  3. txtfile = open(‘a.txt’, ‘r’)
    txtfile.readlines()
  4. txtfile = open(‘a.txt’, ‘r’)
    txtfile.reads()

Answer: 1
Explanation: txtfile.read() Read at most n characters from stream. This method will read from underlying buffer until we have n characters or we hit End of file. If n is negative or omitted, read until End of file.

Q2. Which of the following creates iterable elements?

  1. continue
  2. range
  3. break
  4. pass

Answer: 2
Explanation: range(stop) -> range object
range(start, stop[, step]) -> range object
Return an object that produces a sequence of integers from start (inclusive)to stop (exclusive) by step. range(i, j) produces i, i+1, i+2, …, j-1. start defaults to 0, and stop is omitted! range(4) produces 0, 1, 2, 3. These are exactly the valid indices for a list of 4 elements. When step is given, it specifies the increment (or decrement).

Q3. Which of the following is default mode in open() function?

  1. ‘a’ – append
  2. ‘w’ – write
  3. ‘r’ – read
  4. ‘x’ – create

Answer: 3
Explanation: ‘r’ => open for reading (default).

Q4. In s1 = “theai” and s2 = “learner”. Output of the print(2*s1[:2]+s2) will be:

  1. thethelearner
  2. eelearner
  3. thlearner
  4. ththlearner

Answer: 4
Explanation: => print(2*s1[:2]+s2)
=> print(2*’th’+s2)
=> print(‘thth’+s2)
=> print(‘ththlearner’)
=> ththlearner

Q5. In Python scope, what does LEGB rule stands for?

  1. Local, Enclosed, Global, and Basic
  2. Local, Enclosing, General, and Built-in
  3. Local, Enclosing, Global, and Basic
  4. Local, Enclosing, Global, and Built-in

Q6. In Python, which of the following rule is used to decide the order in which the namespaces are to be searched for scope resolution?

  1. LEGB rule (Local, Enclosed, General, Built-in)
  2. LEGB rule (Local, Enclosed, Global, Built-in)
  3. ELGB rule (Enclosed, Local, Global, Built-in)
  4. ELGB rule (Enclosed, Local, Genral, Built-in)

Answer: 1
Explanation: Since x1 and x2 refers to the same object in the memory, adding the items in the x2 will also add items in x1.

Q8. if x = [2, 4, 6, 8], which of the following operation will change x to [2, 4, 8]?

  1. del x[2]
  2. x.remove(6)
  3. x[2:3] = []
  4. All of the above!

Answer: 4
Explanation: del x[2] => will delete the item at index 2.
x.remove(6) => will remove the first occurance of value 6.
x[2:3] = [] => will replace the value at index 2 to nothing.

Python Quiz-3

Q1. What will be the output of following code:

  1. a b c
  2. a b
  3. a c
  4. a

Answer: 3
Explanation: continue keyword will skip the rest of the statements after it in the loop and make the loop to run for the next iteration.

Q2. What will be the output of following code:

  1. 18
  2. 12
  3. 9
  4. Error

Answer: 2
Explanation: function which is defined inside another function is known as inner function or nested function. Nested functions are able to access variables of the enclosing scope. Inner functions are used so that they can be protected from everything happening outside the function. This process is also known as Encapsulation.
Reference: Inner Functions
Default arguments in Python

Q3. What are the dunder(magic) methods in Python?

  1. Methods that start with single underscore.
  2. Methods that start with double underscore and ends with double underscore.
  3. Methods that start with double underscore.
  4. Methods that ends with single underscore.

Answer: 2
Explanation: Dunder or magic methods in Python are the methods having two prefix and suffix underscores in the method name. Dunder here means “Double Under (Underscores)”. These are commonly used for operator overloading. Few examples for magic methods are: __init__, __add__, __len__, __repr__ etc.
Reference: Dunder or magic methods in Python

Q4. Which of the following option gives the value of rating2 from the code?

  1. dictionary[“Company”][“Employee”][“Performance”][“rating2”]
  2. dictionary[“Company”][“Employee”][“Performance”][1]
  3. dictionary[“Company”][0][“Performance”][“rating2”]
  4. dictionary[0][“Employee”][“Performance”][“rating2”]

Answer: 1
Explanation: dictionary -> “Company” -> “Employee” -> “Performance” -> “rating2” = 8/10

Q5. Which of the following are main component of JSON in Python?

  1. Arrays and Values
  2. DIctionary and Values
  3. Classes and Objects
  4. Keys and Values

Answer: 4
Explanation: Keys and Values are main component of JSON in Python.

Q6. Which of the following is not a correct statement regarding JSON in Python?

  1. Python has a built-in package called json, which can be used to work with JSON data.
  2. JSON is a syntax for storing and exchanging data.
  3. A Python object can be converted into JSON string using json.create()
  4. A Python object can be converted into JSON string using json.dumps()

Answer: 3
Explanation: A Python object can be converted into JSON string using json.dumps()
Python JSON

Q7. Which of the following is not an iterable Object?

  1. List and tuples
  2. Int
  3. Set
  4. Dictionary

Answer: 2
Explanation: int is a built-in data type and it is not iterable. Lists, tuples, dictionaries, and sets are all iterable objects.

Q8. What will be the output of following code:

  1. {3, 4, 5, 6}
  2. {3, 4}
  3. {1, 2, 3, 4, 5, 6}
  4. {1, 2, 5, 6}

Answer: 4
Explanation: ^ operator will return all the items which are not present in both the sets.

Python Quiz-2

Q1. What will be the output of following code:

  1. 15
  2. 5
  3. 50
  4. Error

Answer: 3
Explanation: A function which is defined inside another function is known as inner function or nested function. Nested functions are able to access variables of the enclosing scope. Inner functions are used so that they can be protected from everything happening outside the function. This process is also known as Encapsulation.
Reference: Inner Functions

Q2. Which of the following function is used inside a for loop in Python?

  1. count()
  2. iterate()
  3. next()
  4. new()

Answer: 3
Explanation: You can read more about Python for loop here:
What’s inside Python ‘for’ loop?

Q3. What will be the output of following code:

  1. 1
    2
    Great!
  2. x
    y
    Great!
  3. 1
    2
    3
    Great!
  4. x
    y
    z
    Great!

Answer: 2
Explanation: If “if” condition is not True then only “elif” condition will execute.

Q4. What will be the output of following code:

  1. 5
  2. 8
  3. 6
  4. TypeError!

Answer: 3
Explanation: len() function gives the length of the tuple.

Q5. Which of the following statement will return False?

  1. bool(-1)
  2. bool(1)
  3. bool(0)
  4. bool(12E5)

Answer: 3
Explanation: Any number is True, except 0.

Q6. Which of the following brackets can be used to create lists in Python?

  1. []
  2. {}
  3. ()
  4. <>

Answer: 1
Explanation: list1 = [] will create a list in Python.

Q7. In Python, what is the correct way of casting an integer value to a string?

  1. x = str(6)
  2. x = Integer.toString(6);
  3. Both of the above.
  4. None of the above.

Answer: 1
Explanation: In Python language, you can cast an integer to a string by using ‘str’ keyword.

Q8. What will be the output of following code:

  1. 0
  2. 1
  3. 2
  4. Throws an error!

Answer: 1
Explanation: count() method returns the number of times a specified value occurs in a string. “a” occurs one time in “”TheAILearner”. But in count method start (0) and end (5) index of the string is given where it will search for “a”.

Python Quiz-1

Q1. Which of the following is true for a lambda function in Python?

  1. A lambda function is a small anonymous function.
  2. A lambda function can take any number of arguments, but can only have one expression.
  3. Lambda functions are used for functional programming.
  4. All of the above.

Answer: 4
Explanation: All of the statements regarding the Python lambda functions are correct.

Q2. Which of the following is the recommended way to ensure that a file object is properly closed after usage?

  1. Use close() function after the use of file object.
  2. Use try/finally block
  3. Use with statement
  4. All of the above.

Answer: 3
Explanation: When you open a file using with keyword, the file is automatically closed after leaving the block, and all the resources that are tied up with the file are released.

Q3. What will be the output of following code:

  1. 0 2 3
  2. 0 16 24
  3. 48 64 72
  4. 32 96 128

Answer: 3
Explanation: sys.getsizeof(object, default) return the size of object in bytes.

Q4. Which of the following list assignment in Python will throw an exception?

  1. x = [1, 2, ‘python’]
  2. x = [1, 2, [1, 2]]
  3. x = [‘a’, ‘b’, ‘c’, ‘a’, ‘4.5’, int(3.4)]
  4. None of the above.

Answer: 4
Explanation: in Python language, list items can be of any data types and also a list can contain different data types.

Q5. What will be the output of following code:

  1. <class ‘tuple’>
  2. <class ‘str’>
  3. <class ‘list’>
  4. <class ‘int’>

Answer: 2
Explanation: To create a tuple with single item, we need to add comma(,) at the end of the item.

Q6. If str = “AILearner”, what will be the output of print(str == ‘AILearner’, str is “AILearner”)?

  1. False False
  2. True False
  3. False True
  4. True True

Answer: 4
Explanation: In Python language, “is” keyword is used to test if the two variables refers to the same object.

Q7. What will be the output of print(13//2)?

  1. 6.5
  2. 6
  3. 7
  4. Throws an error.

Answer: 2
Explanation: In Python language, // is a floor division operator. This operator will divide the two numbers and round up it to the previous lower integer.

Q8. What will be the output of following code:

  1. 1120
  2. ‘a’
  3. -1120
  4. TypeError

Answer: 4
Explanation: max() does not support comparison between instances of ‘str’ and ‘int’.