0% found this document useful (0 votes)
8 views3 pages

Answer The Two Mark Questions

The document provides concise answers to various Python-related questions, covering topics such as keywords, indentation, comments, complex numbers, operators, type functions, and data types. It explains the significance of each concept and provides examples for clarity. Additionally, it discusses operator precedence and associativity in Python.

Uploaded by

devildevil51689
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)
8 views3 pages

Answer The Two Mark Questions

The document provides concise answers to various Python-related questions, covering topics such as keywords, indentation, comments, complex numbers, operators, type functions, and data types. It explains the significance of each concept and provides examples for clarity. Additionally, it discusses operator precedence and associativity in Python.

Uploaded by

devildevil51689
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/ 3

Absolutely! Let's tackle these Python two-mark questions.

Since the questions are designed for


brevity, I'll keep the answers concise.
1. Define Keywords? Give examples.
Keywords are reserved words in Python that have specific meanings and cannot be used as
identifiers (variable names, function names, etc.). They are fundamental parts of the language's
syntax.
Examples: if, else, for, while, def, return, True, False, None
2. What is Indentation?
Indentation refers to the spaces or tabs used at the beginning of a line in Python to define code
blocks (like within loops, functions, conditional statements, etc.). It's crucial in Python as it
determines the structure and grouping of statements, unlike many other languages that use
curly braces.
3. How to specify comments in python?
●​ Single-line comments: Use the # symbol. Anything after # on that line is ignored as a
comment.​
# This is a single-line comment​
x = 10 # This is also a comment​

●​ Multi-line comments (docstrings): Use triple quotes (""" or '''). These are often used for
documenting functions and classes.​
"""​
This is a multi-line comment or docstring.​
It can span multiple lines.​
"""​

4. What is complex() function?


The complex() function is used to create complex numbers in Python. Complex numbers have a
real and imaginary part.
Example: z = complex(2, -3) (z will be 2 - 3j)
5. List the bitwise operators in python?
●​ & (Bitwise AND)
●​ | (Bitwise OR)
●​ ^ (Bitwise XOR)
●​ ~ (Bitwise NOT)
●​ << (Left shift)
●​ >> (Right shift)
6. List the Logical and Relational operators in python?
●​ Logical Operators:
○​ and
○​ or
○​ not
●​ Relational Operators:
○​ > (Greater than)
○​ < (Less than)
○​ >= (Greater than or equal to)
○​ <= (Less than or equal to)
○​ == (Equal to)
○​ != (Not equal to)
7. Illustrate the use of type() function?
The type() function returns the data type of an object.
Example:
x = 10​
print(type(x)) # Output: <class 'int'>​

y = "hello"​
print(type(y)) # Output: <class 'str'>​

8. With example illustrate 'is' and 'is not' operator?


is checks if two variables refer to the same object in memory. is not is the opposite. == checks
for value equality, while is checks for object identity.
Example:
x = [1, 2, 3]​
y = x # y now refers to the same list as x​
z = [1, 2, 3] # z is a new list with the same elements as x​

print(x is y) # Output: True (same object)​
print(x is z) # Output: False (different objects)​
print(x == z) # Output: True (same value)​

9. Why python is called strongly typed language?


Python is called strongly typed because the type of a variable is strictly enforced. Once a
variable is declared with a type, it cannot be easily changed to another incompatible type
implicitly. This helps prevent type errors during runtime.
10. What is type conversion?
Type conversion (or type casting) is the process of changing a variable from one data type to
another explicitly.
Example:
x = 10​
y = float(x) # Converts x to a float (10.0)​

11. List the data types in python?


●​ Numeric: int, float, complex
●​ String: str
●​ Boolean: bool
●​ Sequence: list, tuple, range
●​ Mapping: dict
●​ Set: set
12. What is identifier? List the rules for defining identifier in python?
An identifier is a name given to a variable, function, class, module, or other entity in Python.
Rules for defining identifiers:
●​ Must start with a letter (A-Z, a-z) or an underscore (_).
●​ Can contain letters, digits (0-9), or underscores.
●​ Case-sensitive (e.g., myVar and myvar are different).
●​ Cannot be a keyword.
13. What is chr and ord functions?
●​ chr(n): Returns the string representing the character whose Unicode code point is the
integer n.
●​ ord(c): Returns the integer representing the Unicode code point of the single-character
string c.
Example:
print(chr(65)) # Output: A​
print(ord('A')) # Output: 65​

14. What is operator precedence?


Operator precedence is the order in which operators are evaluated in an expression. Python
follows standard precedence rules (like PEMDAS/BODMAS in mathematics).
Example: 2 + 3 * 4 (Multiplication is done before addition)
15. What is operator Associativity?
Operator associativity determines the order of evaluation when operators of the same
precedence appear in an expression. It can be left-to-right or right-to-left.
Example: 2 ** 3 ** 2 (Exponentiation is right-to-left, so it's evaluated as 2 ** (3 ** 2))

You might also like