20ES2103B - Python Programming - Answers For Short Questions - UNIT - I & II
20ES2103B - Python Programming - Answers For Short Questions - UNIT - I & II
20ES2103B - Python Programming - Answers For Short Questions - UNIT - I & II
Keyword Description
Operator Description
<=
< Comparison
> Operators
>=
<>
Equality
==
Operators
!=
not
or Logical Operators
and
name = "Fredric"
print(name[::-1])
Output:
cirderF
a % b
Example:
x = 10
y = 2
mod = x % y
print("Modulo of the numbers: ", mod)
Output:
Modulo of the numbers: 0
8. What are python modules? Name some commonly used built-in modules in Python?
Module: A module is a file containing Python definitions and statements. A module can define
functions, classes, and variables. A module can also include runnable code. Grouping related code
into a module makes the code easier to understand and use. It also makes the code logically
organized. Programmer can import modules from packages using the dot (.) operator.
Modules in Python can be of two types: Built-in Modules, User-defined Modules.
Ex: date.py, sqrt.py, etc.
x = "Python"
print("String: ", x)
print(type(x))
Output:
String: Python
<class 'str'>
ii) Lists: They are just like the arrays, declared in other languages which is an ordered collection
of data. It is very flexible as the items in a list do not need to be of the same type.
Output:
Output:
12. List any 10 built-in functions in Python along with their functionalities.
Function Description
13. Explain int() and float() type conversions in Python with example.
1) int(): This function converts any data type to integer
2) float(): This function is used to convert any data type to a floating-point number
string = "10010"
conv_int = int(string)
conv_float = float(string)
print("Before converting: ", string)
print("After converting to integer : ",conv_int)
print("After converting to float : ", conv_float)
Output:
import random
rand_num = random.random()
print("Random float between 0 and 1:", rand_num)
Output:
import random
rand_num = random.randint(0,22) # (first,last)
print("Random number in the range:", rand_num)
Output:
16. List out any 10 math functions in ‘math’ module with functionalities.
Function Description
a = True
b = False
print(a and b)
Output:
False
18. Use the lambda() function to find the sum of the integers 5, 6 and 2.
x = lambda a, b, c : a + b + c
print(x(5, 6, 2))
Output:
13