Pythhon Exam
Pythhon Exam
Built-in functions are pre-defined functions that are available for use
without requiring import or installation of additional libraries.
following are some important Built-in functions.
1. abs()
Example:
>>>abs(3)
>>>abs(-3)
Output:
2. min()
The min() function returns the smallest of two or more
arguments.
Example:
>>> min(10, 2, 7, 8, 5)
Output: 2
3. max()
Example:
>>> max(10, 2, 7, 8, 5)
Output:
10
4. divmod()
The divmod() function is used to perform
both division and modulus (remainder) operations
simultaneously on two numbers. It returns a tuple containing
the quotient and the remainder when one number is divided
by another.
Example:
Output:
(2, 1)
5. pow()
Example:
>>> pow(3, 2)
Output:
9
5. len()
Example:
>>> len("Python")
Output: 6
In Python, the continue and break statements are control flow statements used
within loops to alter their behavior.
continue Statement:
The continue statement is used to skip the rest of the code inside a loop for
the current iteration and move to the next iteration.
if i % 2 == 0:
print(i)
In this example, the continue statement is used to skip the print(i) statement
for even numbers, and it moves to the next iteration of the loop.
break Statement:
The break statement is used to exit a loop prematurely, stopping further
iterations even if the loop condition is not fully satisfied.
i=1
if i > 5:
# Stop the loop when the first number greater than 5 is found
break
print(i)
i += 1
Output: 1 2 3 4 5
In this example, the break statement is used to exit the while loop prematurely
when i becomes greater than 5, even though the loop condition ( i <= 10) is
still satisfied.
Both continue and break statements provide a way to control the flow of a loop
based on specific conditions, allowing for more flexibility in loop execution.
else:
Python provides a module called sys that allows you to access command-
line arguments through the sys.argv list. The sys.argv list contains all
the arguments passed to the script, including the script’s name itself as the
first element (at index 0).
Example: import sys
Output: C:\Users\Admin\AppData\Local\Programs\Python\Python311\Example.py
Example:
person_detail(name="Devika", city="Aurangabad")
person_detail(city="Jaipur", name="Raj")
Output:
Devika is leave in Aurangabad
x = 10
del x
# Now, the variable x is no longer defined
my_list = [1, 2, 3, 4, 5]
del my_list[2]
my_variable = [1, 2, 3]
del my_variable
my_object = SomeClass()
del my_object
# The entire object instance my_object is deleted
my_list = [1, 2, 3, 4, 5]
del my_list[1:3]
1. for Loop:
The for loop is used to iterate over a sequence (such as a list,
tuple, string, or range) and execute a block of code for each
element in the sequence.
while Loop:
The while loop is used to repeatedly execute a
block of code as long as a specified condition is
true.
write short note on range () function in python?
The range() function in Python is a built-in function that is used to
sequence of numbers.
Syntax:
range(stop)
range(start, stop)
Examples:
print(i)
# Output:
#1
#3
#5
#7
#9
print(my_list)
# Output: [3, 5, 7, 9]
1. Void Function
#Function Definition
def add(num1,num2):
print(num1+num2)
#Function Calling
Output: 30
add(10,20)
2. Return Statement:
caller.
Example: In this example, the add function takes two parameters and
returns their sum. The value returned by the function is assigned to the
#Function Definition
def add(num1,num2):
return num1+num2
#Function Calling
result = add(10,20)
print(result)
Output: 30
Explain the type function and Is operator with
example?
Definition
Python type() is a built-in function that returns the type of the
objects/data elements stored in any data type or returns a new type
object depending on the arguments passed to the function.
The Python type() function prints what type of data structures are
used to store the data elements in a program.
Python Type()
In Python, we do not explicitly specify the data type of the variable for
storing data elements. Hence, if we want to find out what type of data is
stored in a variable we use Python’s built-in type() function. Python
type() is a built-in function that is used to print the type of function
parameters based on the arguments passed to it. There are 2 different
forms of type() functions i.e. there are 2 different methods to pass the
arguments into the type() function.
a = 10
b = 10.5
c = True
d = 1 + 5j
print(type(a))
print(type(b))
print(type(c))
print(type(d))
output:
<class 'int'>
<class 'float'>
<class 'bool'>
<class 'complex'>