Explore topic-wise InterviewSolutions in Current Affairs.

This section includes 7 InterviewSolutions, each offering curated multiple-choice questions to sharpen your Current Affairs knowledge and support exam preparation. Choose a topic below to get started.

1.

Write note on format function?

Answer»
FunctionDescriptionSyntaxExample
format()Returns the outputs the number in base 2.
2. octal format. Outputs the number in base 8.
3. Fixed-point notation. Displays the number as a fixed-point number.
The default precision is 6.
format(value[,format_spec])x = 14
y = 25
Print ('x value in binary:',format(x,'b')
Print ('y value in octal:',format(y,'o)')
Print ('y value in Fixed-point no:',format(y,'f'))
output :
x value in binary : 1110
y value in octal : 31
y value in Fixed-point no: 25,000000



 
2.

Find the output?Program:x = 0 # global variabledef add ( ):global xx = x + 5 # increment by 2print (“Inside add ( ) function x value is:” , x)add ( )print (“In main x value is x)

Answer»

Output:

Inside add ( ) function x value is: 5.

In main x value is: 5

3.

Write note on return statement?

Answer»

The return Statement

1. The return statement causes your function to exit and returns a value to its caller. The point of functions in general is to take inputs and return something.

2. The return statement is used when a function is ready to return a value to its caller. So, only one return statement is executed at run time even though the function contains multiple return statements.

3. Any number of ‘return’ statements are allowed in a function definition but only one of them is executed at run time.

4.

Give the syntax for defining variable – length arguments.?Syntax – Variable – Length Arguments:

Answer»

def function _name (*args): 

function_body

return_statement

5.

Define nested blocks?

Answer»

Nested Block:

A block within a block is called nested block. When the first block statement is indented by a single tab space, the second block of statement is indented by double tab spaces.

6.

What are the two methods of passing arguments in variable length arguments?

Answer»

In Variable Length arguments we can pass the arguments using two methods.

1. Non keyword variable arguments

2. Keyword variable arguments

7.

Classify Function Arguments?

Answer»

1. Required arguments

2. Keyword arguments

3. Default arguments

4. Variable – length arguments

8.

Any Loop can be converted to recursive functions. True / False

Answer»

Any Loop can be converted to recursive functions True

9.

Write the output for the program given below?

Answer»

Program:

def printdata (name, age):

print (“Example – 3 Keyword arguments”)

print (“Name :” ,name)

print (“Age age)

return

# Now you can call printdata ( ) function

printdata (age = 25, name = “Gshan”)

Output:

Example – 3 Keyword arguments

Name: Gshan

Age: 25

10.

Define default arguments?

Answer»

Default Arguments

In Python the default argument is an argument that takes a default value if no value is provided in the function call. The following example uses default arguments, that prints default salary when no argument is passed, def printinfo(sal=3500):

11.

Differentiate parameters and arguments?

Answer»

Parameters are the variables used in the function definition whereas arguments are the values we pass to the function parameters

12.

The default precision for fixed point number is ……(a) 2(b) 4 (c) 6 (d) 8

Answer»

The default precision for fixed point number is 6

13.

Write the rules of local variable?

Answer»

Rules of local variable: 

1. A variable with local scope can be accessed only within the function/block that it is created in. 

2. When a variable is created inside the function/block, the variable becomes local to it. 

3. A local variable only exists while the function is executing. 

4. The formate arguments are also local to function.

14.

What is composition in functions?

Answer»

The value returned by a function may be used as an argument for another function in a nested manner. This is called composition. For example, if we wish to take a numeric value or an expression as a input from the user, we take the input string from the user using the function input ( ) and apply eval ( ) function to evaluate its value

15.

What are the points to be noted while defining a function?

Answer»

1. Function blocks begin with the keyword “def ” followed by function name and parenthesis ( ).

2. Any input parameters or arguments should be placed within these parentheses when you define a function.

3. The code block always comes after a colon (:) and is indented.

4. The statement “return [expression]” exits a function, optionally passing back an expression to the caller. A “return” with no arguments is the same as return None

16.

Which of the following keyword is used to define the function testpython():?(a) Define(b) Pass(c) Def(d) While

Answer»

Def is used to define the function testpython():

17.

Write the different types of function?

Answer»

1. User – defined Functions

2. Built – in Functions

3. Lambda Functions

4. Recursion Functions

18.

Pick the correct one to execute the given statement successfully.if_: print (x, ” is a leap year”)(a) x % 2 = 0(b) x % 4 = = 0(c) x / 4 = 0(d) x % 4 = 0

Answer»

(b) x % 4 = = 0

19.

Read the following statement and choose the correct statement(s).(I) In Python, you don’t have to mention the specific data types while defining function.(II) Python keywords can be used as function name.(a) (I) is correct and (II) is wrong (b) Both are correct(c) (I) is wrong and (II) is correct(d) Both are wrong

Answer»

(a) (I) is correct and (II) is wrong

20.

Evaluate the following functions and write the output?

Answer»

Output:

(i) 1. 13

2. 3.2

(ii) 1. 50

2. 36

(iii) <class 'str'>

(iv) 0b10000

(v). 1. CR (carriage return)

2. It moves the cursor to the beginning of same line 

(vi) 1. 8.2 

2. 18.0 

3. 0.510

4. 0.512

(vii) 1. B 

2. a 

3. A 

4. 6 

5. 10

(viii) 1. 0.125

2. 8.0

3. 1

21.

bin ( ) returns the binary string prefixed with ………… for the given integer number(a) b(b) ob(c) obin(d) bin

Answer»

bin ( ) returns the binary string prefixed with ob for the given integer number

22.

Find the correct statement.(a) Local and global variables cannot be used in the same code(b) Local and global variables can be used in the same code

Answer»

(b) Local and global variables can be used in the same code

23.

…………. function is the alternative for bin ( ) function.(a) Ord ( )(b) Format ( )(c) Binary ( )(d) Ord ( )

Answer»

(b) Format ( )

24.

The ………… function is the inverse of chr ( ) function.(a) Ord ( )(b) Abs ( )(c) Chr ( )(d) Bin ( )

Answer»

The Ord ( ) function is the inverse of chr ( ) function.

25.

Read the following statement and choose the wrong statements(a) Without using the global keyword, we cannot modify the global variable(b) Using global keyword we can modify the global variable(c) Without global keyword, we can modify the global variable

Answer»

(c) Without global keyword, we can modify the global variable

26.

Find the correct one:(a) Global keyword outside the function has no effect(b) Global keyword outside the function has effect

Answer»

(a) Global keyword outside the function has no effect

27.

Lambda functions cannot be used in combination with …….(a) Filter(b) Map(c) Print(d) Reduce

Answer»

Lambda functions cannot be used in combination with Print

28.

In which arguments the correct positional order is passed to a function?(a) Required(b) Keyword(c) Default(d) Variable – length

Answer»

(a) Required

29.

While defining a function which of the following symbol is used.(a) ; (semicolon)(b) . (dot)(c) : (colon) (d) $ (dollar)(c) : (colon)(d) $ (dollar)

Answer»

Answer is (c) : (colon)

30.

Which of the following keyword is used to begin the function block?(a) Define(b) For(c) Finally(d) Def

Answer»

Def is used to begin the function block

31.

A Function which calls itself is called as ………(a) Built – in(b) Recursion(c) Lambda(d) Return

Answer»

A Function which calls itself is called as Recursion

32.

A named blocks of code that are designed to do one specific job is called as ……(a) Loop(b) Branching(c) Function(d) Block

Answer»

A named blocks of code that are designed to do one specific job is called as Function

33.

Which of the following keyword is used to exit a function block?(a) Define(b) Return(c) Finally(d) Def

Answer»

Return is used to exit a function block

34.

Which function is called anonymous un – named function?(a) Lambda(b) Recursion(c) Function(d) Define

Answer»

Lambda is called anonymous un – named function

35.

Write a Python code to check whether a given year is leap year or not?Leap year or not:Program code:

Answer»

n = int (input(“Enter any year”))

if (n % 4 = = 0):

print “Leap year”

else:

print “Not a Leap year”

Output:

Enter any year 2001

Not a Leap year

36.

How many types of scopes are there?(a) 2(b) 3(c) 4(d) 5

Answer»

There are 2 types of scopes

37.

In python’s …….. function supports variable length arguments.(a) Input(b) Write(c) Output(d) Print

Answer»

In python’s Print function supports variable length arguments.

38.

If the return has no argument, …….. will be displayed as the last statement of the output.(a) No(b) None(c) Nothing(d) No value

Answer»

If the return has no argument, None will be displayed as the last statement of the output.

39.

Explain the scope of variables with an example?

Answer»

Scope of Variables:

Scope of variable refers to the part of the program, where it is accessible, i.e., area where you can refer (use) it. We can say that scope holds the current set of variables and their values. The two types of scopes are local scope and global scope.

(I) Local scope:

A variable declared inside the function’s body or in the local scope is called as local variable

Rules of local variable:

1. A variable with local scope can be accessed only within the function/block that it is created in.

2. When a variable is created inside the function/block; the variable becomes local to it.

3. A local variable only exists while the function is executing.

4. The formate arguments are also local to function.

Example:

Create a Local Variable

def loc ( ):

y = 0 # local scope

print (y)

loc ( )

Output:

0

(II) Global Scope:

A variable, with global scope can be used anywhere in the program. It can be created by defining a variable outside the scope of any function/block.

Rules of global Keyword:

The basic rules for global keyword in Python are:

1. When we define a variable outside a function, it’s global by default. You don’t have to useglobal keyword.

2. We use global keyword to read and write a global variable inside a function.

3. Use of global keyword outside a function has no effect

Example:

Global variable and Local variable with same name 

x = 5 def loc ( ):

x = 10

print (“local x:” , x)

loc ( )

print (“global x:” , x)

Output:

local x: 10

global x: 5

In above code, we used same name ‘x’ for both global variable and local variable. We get different result when we print same variable because the variable is declared in both scopes, i.e. the local scope inside the function loc() and global scope outside the function loc ( ).

The output:- local x: 10, is called local scope of variable.

The output: – global x: 5, is called global scope of variable.

40.

Differentiate ceil ( ) and floor ( ) function?

Answer»
functionDescriptionsyntaxExample
floor ( )Returns the largest integer less than or equal to xx = 26.7
y = -26.7
z = 23.2
Print(math.floor(x))
Print(math.floor(y))
Print(math.floor(z))
Output:
26
-27
-24
ceil ( )Returns the smallest integer greater than or equal to xx = 26.7
y = -26.7
z = 23.2
Print(math.ceil(x))
Print(math.ceil(y))
Print(math.ceil(z))
Output:
27
-26
-23
41.

Lambda function can only access …… variables.(a) Local(b) Function(c) Global(d) Nested

Answer»

Lambda function can only access Global variables

42.

What happens when we modify global variable inside the function?

Answer»

It will change the global variable value outside the function also.

43.

A block of code begins when a line is indented by ………. spaces usually.(a) 2(b) 3(c) 4 (d) 5

Answer»

A block of code begins when a line is indented by 4 spaces usually

44.

A ……. is one or more lines of code, grouped together.(a) Code – (b) Block (c) Function (d) Arguments

Answer»

A Block is one or more lines of code,

45.

Name of the function is followed by ……….(a) ( ) (b) [ ] (c) &lt;&gt; (d) { }

Answer»

Name of the function is followed by ( )

46.

Non – keyword variable arguments are called …………

Answer»

Non – keyword variable arguments are called Tuples

47.

What is the symbol used to denote variable – length arguments?(a) +(b) *(c) &amp;(d) ++

Answer»

* is the symbol used to denote variable – length arguments

48.

A block within a block is called ……block.

Answer»

A block within a block is called Nested block.

49.

Write the basic rules for global keyword in python?

Answer»

The basic rules for global keyword in Python are:

1. When we define a variable outside a function, it’s global by default. You don’t have to use global keyword.

2. We use global keyword to read and write a global variable inside a function.

3. Use of global keyword outside a function has no effect

50.

The arguments can be given in improper order in ………. arguments.(a) Required(b) Keyword(c) Default(d) Variable – length

Answer»

The arguments can be given in improper order in Keyword arguments.

Previous Next