Page 101 - PYTHON-12
P. 101
13. What are the built-in data types that Python provides?
Ans. There are mutable and immutable data types of Python built-in data types. Mutable built-in data types offered
by Python are:
• List
• Sets
• Dictionaries
Immutable built-in types are:
• Strings
• Numbers
14. What is pass in Python?
Ans. pass means no-operation Python statement or, in other words, a placeholder in compound statement where
there should be a blank left and nothing should be written there.
15. What is negative index in Python?
Ans. Python sequences can be indexed using both the positive and negative numbers. For positive index, 0 is the
first index, 1 is the second index, so on and so forth. For negative index, (–1) is the last index and (–2) is the
second-last index and so on.
16. How can you convert a number into a string?
Ans. In order to convert a number into a string, use the inbuilt function str(). If you want an octal or hexadecimal
representation, use the inbuilt function oct() or hex().
17. Which operator checks a value’s presence in a list of values?
Ans. in
18. In file handling, what does the terms ‘r’, ‘a’ stand for?
Ans. ‘r’ stands for read and ‘a’ stands for append.
19. What do you understand by module and package in Python?
Ans. In Python, module is the way to structure a program. Each Python program file is a module which imports
other modules like objects and attributes.
The folder of a Python program is a package of modules. A package can have modules or sub-folders.
20. What are the rules for local and global variables in Python?
Ans. Local variables: If a variable is assigned a new value anywhere within a function’s body, it is assumed to be
local.
Global variables: Those variables that are only referenced inside a function are implicitly global.
21. How do you access and modify a global variable in Python?
Ans. Global variables are accessible throughout the program and inside every function. However, to change the
value of the global variable from within a function, we use global keyword.
22. Explain how to delete a file in Python.
Ans. A file can be deleted by using a command os.remove(filename) or os.unlink(filename).
23. Explain how you can generate random numbers in Python.
Ans. To generate random numbers in Python, we need to import command as:
import random
random.random()
This returns a random floating-point number in the range [0.0,1.0).
24. Mention five benefits of using Python.
Ans. (a) Python comprises a huge standard library for most internet platforms like email, HTML, etc.
(b) Python does not require explicit memory management as the interpreter itself allocates memory to new
variables and frees them automatically.
(c) It provides easy readability due to the use of square brackets.
(d) It is easy to learn for beginners.
(e) Having built-in data types saves programming time and effort from declaring variables.
Appendices A.29