0% found this document useful (0 votes)
4 views2 pages

Programming in Python Answers

The document provides exam answers related to Python programming, covering topics such as basic programming constructs, data types, functions, and object-oriented programming concepts. It includes code snippets, explanations of escape characters, modules, and the differences between Python and C. Additionally, it discusses Python execution, operators, and array and string operations.

Uploaded by

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

Programming in Python Answers

The document provides exam answers related to Python programming, covering topics such as basic programming constructs, data types, functions, and object-oriented programming concepts. It includes code snippets, explanations of escape characters, modules, and the differences between Python and C. Additionally, it discusses Python execution, operators, and array and string operations.

Uploaded by

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

Programming in Python - Exam Answers

PART A

1. Program to print sum of 2 numbers:


a = 10
b = 20
print("Sum =", a + b)

2. Escape characters: \n, \t, \\, \', \", \r, \b

3. Module: Single Python file containing functions/classes.


Package: Collection of modules in a directory.

4. Math module supports mathematical calculations.

5. Accept integer and display:


num = int(input("Enter number: "))
print(num)

6. Check zero, positive or negative:


if num > 0: Positive
elif num < 0: Negative
else: Zero

7. array() is used to create arrays storing same data type values.

8. Strings are used to store and process text.

9. Function: Outside class. Method: Inside class.

10. Python uses naming conventions for private/public (_var, __var).

11. super() calls parent class methods.

12. Method overloading: Same method name with different parameters (achieved using default
arguments in Python).

PART B

13. Python is interpreted, easy syntax, OOP. C is compiled, faster, procedural.

14. Left shift (<<) multiplies by 2. Right shift (>>) divides by 2.

15. print() examples:


print("Hello")
print("Sum =", 10+20)

16. Nested loop: Loop inside another loop.

17. NumPy: Library for numerical and array operations.

18. Formal arguments are parameters in function definition.


19. Local variables inside function. Global variables outside function.

20. Constructor (__init__) initializes object.

21. In inheritance, use super().__init__() to call parent constructor.

PART C

22. Python execution:


Source code -> Bytecode -> Python Virtual Machine executes.

23. Operators:
Arithmetic, Relational, Logical, Assignment, Bitwise, Membership, Identity.

24. Array operations:


Accessing, inserting, deleting, slicing, traversing.

25. String case operations:


upper(), lower(), title(), capitalize(), swapcase().

You might also like