0% found this document useful (0 votes)
4 views

2.10 th Basics of Python

Uploaded by

umauday1512
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

2.10 th Basics of Python

Uploaded by

umauday1512
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

2.

Basics of Python

A. Fill in the blanks

1. The input () function reads the user’s input value and returns it as a
_________.
Ans. String
2. The valid combination of both operands and operators makes an
________, which returns a computed result.
Ans. Expression
3. The _______ operator is used to combine two or more strings.
Ans. Concatenate (‘+’)
4. ________ operators are used to show the relationship between
operands.
Ans. Relational
5. The order in which the operators are evaluated is called ________
of operators.
Ans. Precedence
B. State True or False

1. An operator does not need any operand to perform operations.


False
2. Unary operators can be used on more than three operators.
False
3. Exponentiation operator is used to calculate the power of numbers.
True
4. Higher precedence operators are operated before the lower
precedence operators
True
5. In python, only one type of data can be stored in memory.
False
C. Select the correct option

1. To give a tab space while printing the statement, you used


________
a) ‘\t’ b)’/t’ c) ‘/p’ d) ‘\n’
Ans). a
2. The floor division (//) operator returns a _____ value.
a) String b) integer c) float d) Boolean
Ans) b
3. Which of the following represents the type of data stored in a
variable?
a) Operator b) escape sequence c) keyword d) data type
Ans). d
4. ______ tells the direction of execution of operators when operators
in an expression have the same precedence.
a) Precedence b) associativity c) operands
b) d) string replication
Ans). b
5. Which of the following is the symbol of modulus operator?
a) * b) % c)// d) **
Ans). c
6. Which of the following is the symbol of the assignment operator?
a) == b) = c)// d) \\
Ans). b
D. Name the following

1. Name the function that prompts the user to give input.


Ans). input ()
2. It is an operator used to perform exponentiation.
Ans). **
3. It is an escape sequence to start with a new line.
Ans). \n
4. These operators operate on only one operand.
Ans). unary operator
5. It is used to find the remainder when one value is divided by another.
Ans). %
6. It is the data type that represents floating point values.
Ans). float
E . Answer the following

1. What are the data types? List some common data type used in python.
Ans). The type of data value that can be stored in a variable is known as
its data type. The data types help in classifying different types of data values
used in a program. Python language has standard data types that are used to
define operations performed on them and the storage method for each. The main
data types used in Python are: int, float, and string.
2. Describe the use of the input (). Write a one-line example to take the input
of a float value from the user.
Ans).The input () function is used to accept the value of a variable from
the user. When you call the input () function, it displays a prompt (if specified)
and then waits for the user to input a value. This value is always considered as a
string, whether it is a number or any other data type.
In this example, the input (“Enter a float value:”) statement prompts the user to
enter a float value.

3. What are escape sequences? List any two.


Ans). Escape sequences in Python are special character combinations that
are preceded by a backslash, used to represent non-printable or difficult-to-type
characters within strings.
Here are two common escape sequences:
• `\n`: Represents a newline character. It is used to start a new line in a string.
• `\t`: Represents a tab character. It is used to insert a horizontal tab in a string.

4. The floor division (//) is different from the basic division (/). Explain.
Ans). ‘/’ operator is used to divide the numbers and give an output in the
decimal form. For example: 5/2 = 2.5, -5/2 = -2.5, 10.0/3 = 3.333.
‘//’ operator is used to divide the numbers and give an output in the integer
form. For example: 5//2 = 2, -5//2 = -2.

5. What is the use of the print () function? Give an example.


Ans). The print () function in Python is used to display a message or value.
It converts the message or an object into a string before writing it on the screen.
It can have multiple parameters. It supports multiple escape sequences to format
the output.
Here’s an example of using the `print () ` function to display a message.
print (“Hello, world!”).
In this example, the `print ()` function to display the message “Hello, world!” .
6. Distinguish between relational and logical operators.
Ans). Relational operators are used to compare the values of operands or
variables and determine the result in a Boolean expression, which is either
'True' or 'False'. The following are the different types of relational operators -
Less than, less than or equal to, Equal to, Greater than, Greater than or equal to,
Not equal to. The Logical or Boolean operators are used to combine two or
more conditional statements. They provide the result in the form of True or
False. We use these operators in Python to make comparisons. There are mainly
three types of Boolean operators -AND, OR, and NOT.

You might also like