Page 45 - PYTHON-11
P. 45
29. What is the difference between an expression and a statement in Python?
Ans.
Expression Statement
An expression is a combination of symbols, A statement is defined as any programming
operators and operands. instruction given in Python as per the syntax.
An expression evaluates to some value. A statement is given to execute a task.
The outcome of an expression is always a value, for A statement may or may not return a value as the
example, 3*7 + 10 is an expression. result. For example,
print ("Hello") is a statement.
30. What is the following statement termed as?
a, b, c, d = 1, 2, 3, 4
Ans. Multiple Assignment Statement, where a=1, b=2, c=3, d=4.
31. What are mutable data types in Python?
Ans. Mutable types in Python means those data types whose values can be changed at the time of execution.
They are as follows:
(a) Lists (b) Dictionaries
(c) Sets
32. Define input() method.
Ans. The purpose of input() method is to fetch some information from the user during the execution of a
program and store it in a variable.
33. What is the role of a print() function?
Ans. A print() method prints an expression which may be a variable’s value or string or a blank line.
34. If you don’t use the sep argument with print() function, then what will it print?
Ans. If sep argument is not defined, then by default separator space is printed between the values received by
the print() statement.
35. What is the default value printed by giving end argument to print() method?
Ans. A new line ('\n') delimiter is the default value printed by giving end argument to print() method.
36. What is the default data type of input fetched from the user using input() function?
Ans. String or str is the default type of input fetched from the user using input() function.
37. What is an operator in Python?
Ans. An operator is a symbol or token that operates on data items or values and performs specific mathematical
or logical operations, ultimately computing a result.
For example, +, -, *, /, %, >, <, >=, <=, <<, >>, &, |, ^, ==, etc.
38. Differentiate between '=' and '==' operator.
Ans. '=' is an assignment operator whereas '==' is a comparison or equality operator and checks for the equality
of two operands or values.
For example: x=9 #Assignment operator
if age==18: #Equality/comparison operator
print("eligible to vote")
39. When does a logical and operator produce True result?
Ans. The logical and operator evaluates to True only if both conditions or operands are true.
40. What is modulo operator? Give an example.
Ans. The % operator is termed as modulo operator. It returns the remainder of a division. For example, 5%2 shall
return the result as 1.
41. Which operator is used to compare the values of operands?
Ans. Relational operators such as >, <, ==, <=,>=, etc., are used to compare the values of operands and produce
a boolean result either True or False.
42. What is a unary operator? Give examples.
Ans. The operator which requires only one operand to operate upon is called unary operator. The + and –
operators in Python can be used in both binary and unary forms.
For example, p=–89, here – is a unary operator.
V.3