0% found this document useful (0 votes)
5 views1 page

Python Ch1 Viva

This document contains a series of 2-mark questions and answers related to Python programming. It covers fundamental concepts such as variables, keywords, operator precedence, string concatenation, and function definitions. Additionally, it explains the use of built-in functions and modules in Python.

Uploaded by

naganannya706
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)
5 views1 page

Python Ch1 Viva

This document contains a series of 2-mark questions and answers related to Python programming. It covers fundamental concepts such as variables, keywords, operator precedence, string concatenation, and function definitions. Additionally, it explains the use of built-in functions and modules in Python.

Uploaded by

naganannya706
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
You are on page 1/ 1

Grand Viva Prep: Python Programming (Chapter 01)

------------------------------------------------
2-Mark Questions & Answers

1. Define a variable in Python and give an example.


Ans: A variable is a name that refers to a memory location holding a value. E.g., x = 10
assigns the integer 10 to the variable x.

2. What is a keyword? Name any two Python keywords.


Ans: Keywords are reserved words with special meaning; they cannot be used as identifiers.
Examples: def, return.

3. Differentiate between expression and statement in Python.


Ans: An *expression* produces a value (e.g., 3+4). A *statement* performs an action such
as assignment or function call (e.g., x = 3+4).

4. Explain 'operator precedence' with an example.


Ans: Operator precedence defines the order in which operations are evaluated. In 3 + 4 *
2, multiplication occurs first giving 11.

5. How do you concatenate two strings in Python?


Ans: Use the + operator: 'Hello' + ' World' returns 'Hello World'.

6. What is the purpose of the '#' symbol in Python?


Ans: '#' starts a comment; everything after it on the same line is ignored by the
interpreter.

7. Which built■in function is used to read a value from the keyboard?


Ans: input() reads a line of text from standard input and returns it as a string.

8. Why is the 'int()' function used? Give an example.


Ans: int() converts its argument to an integer type. E.g., int('42') returns the integer
42.

9. State the use of the 'math' module and show how to import it.
Ans: The math module provides mathematical constants and functions. Import with: import
math.

10. What does the term 'composition of functions' mean in Python?


Ans: Calling one function inside another so the output of the inner becomes the input of
the outer, e.g., print(len(str(1234))).

11. Write a one■line Python function that returns the square of a number.
Ans: def square(n): return n**2

12. Distinguish between a parameter and an argument.


Ans: A *parameter* is a variable in a function definition; an *argument* is the actual
value supplied when the function is called.

13. How can you make a user■defined function available in another file?
Ans: Save the function in a .py file (module) and import it using import module_name or
from module_name import func.

14. What is the output of 'print(type(3.0 + 4))'?


Ans: 3.0 + 4 yields 7.0, a float, so <class 'float'> is printed.

15. Give an example of using the 'max()' function with strings.


Ans: max('apple', 'banana', 'cherry') returns 'cherry' because it is lexicographically
greatest.

You might also like