Digital : Python 3 Programming_FP






1. for x in (2,20,200)

    print (x)"





4. 2 20 200

Explanation : x = 2, 20, 200 Here, comma acts as a separator between the numbers. So, only the leftmost value would be assigned to the variable. x = (2, 20, 200) Here ( ) has higher precedence than the comma operator, so, every value will be traversed and right- most value is returned.

2. While using 'bool', all zero values are considered as false and non- zero values are considered as true. Is this true or false?




1.True

Explanation: A value of zero is considered false. Non-zero values are considered true. However, the values TRUE and FALSE are merely aliases for 1 and 0. See Boolean Literals, as well as the IS operator for testing values against a boolean.

3. What is the output of the following code? for x in (1,10,100): print (x)



        1
        10
        100

4. error

4. What command is used to output text from both the Python shell and within a Python module?





2. print()

Explanation: print() is the command you are looking for. The print() function, formally print statement in Python 2.0, can be used to output text from both the python shell and within a python module.

5. Python supports automatic garbage collection.




1. True

Explanation: Some objects are collected immediately when their reference count drops to zero - for instance string literals passed to functions :

Example: print('Tony') 

The string object ‘Tony’ will be created before the function is called and then garbage collected immediately after.

There is a separate process designed to detect loops etc, which gets triggered ever so often based on how many objects have been created since the last garbage collection run

6. Equivalent operation for function pow(x , y) is __.




3. x**y

Explanation: pow() function with two arguments (x,y) – it is equivalent to x**y. pow() function with three arguments (x,y,z) – it is equivalent to (x**y) % z.

7. list[:] output would be printing the __________.





3. Complete list minus first element

Explanation: List[:] output would be printing the complete list minus first element.

8. Which describes bytearrays?



1. Without an argument, an array of size 0 is created; contains a sequence of integers 0-255

Explanation: The bytearray type is a mutable sequence of integers in the range 0 <= x < 256. It has most of the usual methods of mutable sequences, described in Mutable Sequence Types, as well as most methods that the bytes type has, see Bytes and Byte Array Methods.

9. Which methods can be used with list objects?





Lambda, Pop, Clear

3. Decode, Pop, Clear

10. Bitwise operators cannot be utilized on the float type.




1. True

Explanation: Bitwise operations cannot be used on boolean, float, or double, or class types. They are called the bitwise operators because they are used to test, set, or shift the individual bits that make up a value.

11. Which of these options could be used in tuple object?





2. Reverse , Max

12. In what format does the input function read the user input?




2. String

13.    a = -10

         if a:

              print("a's value")

        else:

              print("Sorry nothing will get printed")





1. Error

14. Consider b is frozen set, what happens to b.add(3)?





2. 3 will be added as a constant

15. Which of the following attributes shows the characteristics of Python?




1. Ubiquity




Post a Comment

0 Comments