Chapter 7: Introduction to Python- Notebook Answers
[Link] the following questions:
a. List any two features of Python that make it a better choice compared to other
languages.
Ans.
The instructions in Python are simple. They are more or less similar to the
words used in the English language. This has increased its popularity.
Python does not require a semicolon or curly braces to end a statement, unlike
many other languages.
b. List the rules to be followed while selecting a name for the variable.
Ans.
A variable name can only contain alphabets, numeric digits and underscores
(A-Z, a-z, 0-9, _ ). You cannot use special characters such as!.@,#,$,% etc. in a
variable name.
A variable name must start with either a letter or an underscore. It cannot
start with a numeric digit or any other character.
c. What are comments used for in Python? How do you indicate a comment in a
program?
Ans:
The notes that we add in our program to help us, or others using our program to
understand it are called as comments. Comments are ignored by a computer when
the program is executed. In Python, a comment starts with a ‘#’.
Comments can also be used to temporarily disable a command that you do not want
to execute, without deleting it from the program.
d. Explain the use of the int( ) function with an example.
Ans: The int( ) function in Python is used to convert a given value into an integer. It
can take a number in string form or a float and convert it to an integer.
Example: age=int(age)
Here in the example, age is a variable which can hold any values like integer, float etc.
The int ( ) converts age into integer type.