0% found this document useful (0 votes)
50 views11 pages

Python MCQs for AIML Students

The document contains a series of multiple-choice questions related to Python programming, covering topics such as identifiers, object-oriented programming, variable names, and basic syntax. Each question is followed by four answer options and the correct answer is provided. The questions are designed to test knowledge of Python language features and concepts.

Uploaded by

chinnuh121212
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views11 pages

Python MCQs for AIML Students

The document contains a series of multiple-choice questions related to Python programming, covering topics such as identifiers, object-oriented programming, variable names, and basic syntax. Each question is followed by four answer options and the correct answer is provided. The questions are designed to test knowledge of Python language features and concepts.

Uploaded by

chinnuh121212
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Malla Reddy College of Engineering

Multi Choice Questions on Python MCQ ()


Department of AIML
1. What is the maximum possible length of an identifier?

a. 16

b. 32

c. 64

d. None of these above

Ans : D

2. Who developed the Python language?

a. Zim Den

b. Guido van Rossum

c. Niene Stom

d. Wick van Rossum

Ans: B

3. In which year was the Python language developed?

a. 1995

b. 1972

c. 1981

d. 1989

Ans: D
4. In which language is Python written?

a. English

b. PHP

c. C

d. All of the above

Ans : C

5. In which year was the Python 3.0 version developed?

a. 2008

b. 2000

c. 2010

d. 2005

Ans: A

6. What do we use to define a block of code in Python language?

a. Key

b. Brackets

c. Indentation

d. None of these

Ans: C

7. Which of the following statements is correct regarding the object-oriented


programming concept in Python?

a. Classes are real-world entities while objects are not real

b. Objects are real-world entities while classes are not real

c. Both objects and classes are real-world entities


d. All of the above

Ans : B

8. class Name:
def __init__(javatpoint):
javajavatpoint = java
name1=Name("ABC")
name2=name1

a. It will throw the error as multiple references to the same object is


not possible

b. id(name1) and id(name2) will have same value

c. Both name1 and name2 will have reference to two different objects
of class Name

d. All of the above

Ans : B

9. What is the method inside the class in python language?

a. Object

b. Function

c. Attribute

d. Argument

Ans: B

[Link] of the following declarations is incorrect?

a. _x = 2

b. __x = 3

c. __xyz__ = 5

d. None of these
Ans: D

11. Why does the name of local variables start with an underscore
discouraged?

a. To identify the variable

b. It confuses the interpreter

c. It indicates a private variable of a class

d. None of these

Ans: C

12. Which of the following is not a keyword in Python language?

a. val

b. raise

c. try

d. with

Ans : A

13. Which of the following statements is correct for variable names in Python
language?

a. All variable names must begin with an underscore.

b. Unlimited length

c. The variable name length is a maximum of 2.

d. All of the above

Ans : B
14. Which of the following declarations is incorrect in python language?

a. xyzp = 5,000,000

b. x y z p = 5000 6000 7000 8000

c. x,y,z,p = 5000, 6000, 7000, 8000

d. x_y_z_p = 5,000,000

Ans : B

15. Which of the following words cannot be a variable in python


language?

a. _val

b. val

c. try

d. _try_

Ans : C

16. Which one of the following has the highest precedence in the expression?

a. Division

b. Subtraction

c. Power

d. Parentheses

ans :D

17. Which of the following is correctly evaluated for this function?

a. (x**y) / z

b. (x / y) * z
c. (x**y) % z

d. (x / y) / z

ANS :C

18. Study the following program:

1. x = 1
2. while True:
3. if x % 5 = = 0:
4. break
5. print(x)
6. x+=1

What will be the output of this code?

a. error

b. 2 1

c. 0 3 1

d. None of these

ANS :A

19. Which one of the following syntaxes is the correct syntax to read from a
simple text file stored in ''d:\[Link]''?

a. Infile = open(''d:\\[Link]'', ''r'')

b. Infile = open(file=''d:\\\[Link]'', ''r'')

c. Infile = open(''d:\[Link]'',''r'')

d. Infile = [Link](''d:\\[Link]'',''r'')

ANS :A

20. Study the following code:

x = ['XX', 'YY']
for i in a:
[Link]()
print(a)

What will be the output of this program?

a. ['XX', 'YY']

b. ['xx', 'yy']

c. [XX, yy]

d. None of these

ANS: A

21. Study the following function:

import math
abs([Link](36))

What will be the output of this code?

a. Error

b. -6

c. 6

d. 6.0

Ans: D

22. Study the following function:

1. any([5>8, 6>3, 3>1])

What will be the output of this code?

a. False

b. Ture
c. Invalid code

d. None of these

Ans : B

23. Study the following statement:

1. >>>"a"+"bc"

What will be the output of this statement?

a. a+bc

b. abc

c. a bc

d. a

Ans: B

24. Study the following code:

>>>"javatpoint"[5:]

What will be the output of this code?

a. javatpoint

b. java

c. point

d. None of these

Ans: C

25. The output to execute string.ascii_letters can also be obtained from:?

a. character

b. ascii_lowercase_string.digits
c. lowercase_string.upercase

d. ascii_lowercase+string.ascii_upercase

Ans : D

26. Study the following code:

1. >>> print (r"\njavat\npoint")

What will be the output of this statement?

a. Java
point
b. java point

c. \njavat\npoint

d. Print the letter r and then javat and then point

Ans : C

27. Study the following statements:

>>> print(0xA + 0xB + 0xC)

What will be the output of this statement?

a. 33

b. 63

c. 0xA + 0xB + 0xC

d. None of these

Ans : A

28. Study the following program:


class book:
def __init__(a, b):
a.o1 = b
class child(book):
def __init__(a, b):
a.o2 = b
obj = page(32)
print "%d %d" % (obj.o1, obj.o2)

Which of the following is the correct output of this program?


a. 32

b. 32 32

c. 32 None

d. Error is generated

Ans : D

29. Study the following program:

class Std_Name:
def __init__(self, Std_firstName, Std_Phn, Std_lastName):
self.Std_firstName = Std_firstName
self. Std_PhnStd_Phn = Std_Phn
self. Std_lastNameStd_lastName = Std_lastName
Std_firstName = "Wick"
name = Std_Name(Std_firstName, 'F', "Bob")
Std_firstName = "Ann"
[Link] = "Nick"
print(name.Std_firstName, name.Std_lastName)

What will be the output of this statement?

a. Ann Bob

b. Ann Nick

c. Wick Bob

d. Wick Nick
Ans : D

30. Study the following statements:

>>> print(ord('h') - ord('z'))

What will be the output of this statement?


a. 18
b. -18
c. 17
d. -17

Ans : B

Common questions

Powered by AI

Python simplifies numerical expression handling through its straightforward use of inherent operators with clear precedence that closely follow mathematical norms. For instance, operators such as power (**), division (/), and unary operations are prioritized in definition to follow a natural arithmetic order . Python’s handling of numerical types like integers, floats, and complex numbers allows for seamless transitions between them during arithmetic operations, which contrasts with languages like C++ where explicit type casting is needed to avoid errors. Additionally, Python’s support for arbitrary precision integers avoids overflows that are common in languages with fixed integer sizes . This makes Python particularly powerful for scientific computing and analysis, often because of its integration with libraries like NumPy for handling arrays and matrices of large numerical data .

While Python is versatile and user-friendly, it presents challenges in high-performance computing (HPC) due primarily to its interpreted nature, which can lead to slower execution speeds compared to compiled languages like C or Fortran . This can impact performance in tasks requiring intensive computations or large datasets. However, these challenges can be mitigated through the use of optimized libraries such as NumPy and SciPy, which offer precompiled high-level math operations that dramatically reduce execution time . Integration with tools like Cython or PyPy can also help optimize performance by compiling Python code into C for speed gains. Moreover, parallel computing frameworks like Dask or integration with GPU-accelerated libraries can further enhance Python’s efficiency in data-intensive applications . These strategies allow developers to leverage Python’s strengths in development ease and maintainability while managing performance concerns in HPC environments.

Python treats strings as immutable sequences of characters, which significantly simplifies memory management internally and aids in string manipulation by allowing easy slicing, concatenation, and repetition with a clean syntax . This immutability ensures that changes result in new string objects rather than modifying existing ones, reducing side effects and potential bugs found in other languages like C, where string handling can involve manually managing memory and buffers. Python’s extensive library offers diverse functionality for common string operations such as search, replace, and change of case, often requiring fewer lines of code and making Unicode support seamless, therefore enhancing both performance and developer productivity .

Python's syntax is highly beneficial for individuals transitioning from non-programming backgrounds because it closely resembles natural language and eschews more complex, rigid syntactic structures found in languages like Java or C++. Its readability allows newcomers to quickly grasp programming concepts without being overwhelmed by syntax errors or compiler messages . The use of whitespace as a control structure enforces code organization without explicit braces or semicolons, which can confuse beginners . Moreover, Python's interactive interpreter fosters experimentation and immediate feedback, which is an engaging approach to learning programming concepts through trial and error . The beginner-friendly syntax coupled with comprehensive standard libraries makes it an excellent introductory language that emphasizes intuition and understanding over rote memorization of syntax .

Python lists are dynamic arrays that support both homogeneous and heterogeneous data types, allowing flexibility in appending and slicing compared to static arrays in Java or C++ that require predefined size . The dynamic nature of lists enables automatic resizing and efficient memory reallocation, thus increasing developer ease in handling varying sequence sizes without intricate pointer arithmetic and memory management. Python lists also provide built-in methods like append(), remove(), and pop() for direct manipulation of elements, enhancing code clarity and brevity . Furthermore, the capacity for nesting lists and accessing elements through negative indices or list comprehensions is not standard in many other languages, offering superior functionality for solving complex algorithmic problems .

Python's implementation of OOP allows dynamic and more flexible structures when compared to statically typed languages like Java or C++. In Python, classes are templates for creating objects, but the same class can define and create objects without explicitly typing the variables at compile time, allowing for more versatile coding . Unlike Java, where classes need to be explicitly declared as public with detailed methods and fields, Python relies on convention rather than enforced access restrictions, such as private variables being indicated by an underscore prefix . Additionally, Python supports multiple inheritance, whereas Java does not, making Python more flexible in this aspect . This results in easier implementation of code but may lead to less strict discipline in large codebases if not carefully managed.

Python is suitable for beginners because of its simple and clean syntax, which is easy to learn and read. It promotes the use of indentation for defining code blocks, which simplifies structure and makes code more readable . Python being an interpreted language means that newcomers can run their programs and get immediate feedback, facilitating faster learning cycles . Additionally, Python's extensive library of modules reduces the need to start coding from scratch and enables greater focus on learning programming concepts rather than dealing with low-level details .

Python uses exceptions to manage errors in a more graceful and controlled manner compared to some traditional languages where error handling has conventionally relied on return codes. This approach enables capturing error states within the flow of the program using try/except blocks, which separates error-handling code from regular code, leading to cleaner and more readable programs . Compared to languages like C++ that use try-catch blocks, Python's simpler syntax with effective builtin exceptions like IOError, ValueError, etc., reduces complexity and potential bugs due to unhandled exceptions leading to crashes . This minimizes unexpected program termination, which is common in languages without integrated exception handling. Consequently, Python's error handling is particularly beneficial in large programs and those involving real-time data processing .

Python enforces certain rules for variable naming that differ slightly from other languages. For instance, Python allows unlimited length for variable names and requires names to start with a letter or underscore, disallowing numbers or symbols . Starting local variables with an underscore is discouraged generally in Python to indicate it should be treated as private—although this is not strictly enforced . This convention is absent in many languages, where underscores can often be used freely without any implied meaning of privacy. The use of significant indentation and naming conventions like underscores aim to maintain readability and a standardized coding style within the Python community, contrasting with languages that prioritize flexibility in syntactic appearance .

Python's philosophy that 'readability counts' profoundly impacts software development by prioritizing code that is not only easy to write but also easy to read and maintain . By enforcing indentation and a clean, readable syntax structure, Python reduces the likelihood of syntactic errors and enhances peer review processes, leading to faster development cycles. This philosophy also aids in debugging by making the structure and flow of programs transparent, thus lowering the cognitive load on developers recoding or updating existing codebases . The standardized format and encouraged use of descriptive variable names and docstrings further improve collaboration on large-scale projects, making Python a preferred choice for teams and open-source software where consistent readability is critical . This can result in better software quality and reduced risk of bugs or vulnerabilities over time .

You might also like