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

Python Function Arguments Explained

The document outlines assertions and reasoning related to functions in Python, providing examples of true/false statements regarding variable scope, argument types, and function definitions. Each assertion is paired with reasoning to clarify the concepts of global variables, positional and keyword arguments, and the structure of function calls. The content serves as a study guide for understanding Python functions and their characteristics.

Uploaded by

A.S.Vishwaa
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)
23 views3 pages

Python Function Arguments Explained

The document outlines assertions and reasoning related to functions in Python, providing examples of true/false statements regarding variable scope, argument types, and function definitions. Each assertion is paired with reasoning to clarify the concepts of global variables, positional and keyword arguments, and the structure of function calls. The content serves as a study guide for understanding Python functions and their characteristics.

Uploaded by

A.S.Vishwaa
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

VELAMMAL VIDYALAYA – SHOLINGANALLUR.

XII – COMPUTER SCIENCE (083) - FUNCTIONS


ASSERTION AND REASONING
(A) Both A and R are true and R is the correct explanation for A
(B) Both A and R are true and R is not the correct explanation for A
(C) A is True but R is False
(D) A is false but R is True
1. Assertion (A): A variable declared as global inside a function is visible with changes
made to it outside the function.
Reasoning (A): All variables declared outside are not visible inside a function till they are
redeclared with global keyword.
Ans:
2. Assertion (A): - If the arguments in a function call statement match the number and
order of arguments as defined in the function definition, such arguments are called
positional arguments.
Reasoning (R): - During a function call, the argument list first contains default
argument(s) followed by positional argument(s).
Ans:
3. Assertion (A):- In Python, statement return [expression] exits a function.
Reasoning (R):- Return statement passes back an expression to the caller. A return
statement with no arguments is the same as return None.
Ans:
4. Assertion (A): - keyword arguments are related to the function calls.
Reasoning (R): - when you use keyword arguments in a function call, the caller identifies
the arguments by parameter name.
Ans:
5. Assertion(A): Function is defined as a set of statements written under a specific name
in the python code.
Reason(R): The complete block (set of statements) is used at different instances in the
program as and when required, referring the function name. It is a common code to
execute for different values(arguments), provided to a function.
Ans:

1
6. Assertion (A): - print(f1()) is a valid statement even if the function f1() has no return
statement.
Reasoning (R): - A function always returns a value even if it has no return statement.
Ans:
7. Assertion: The default value of an argument will be used inside a function if we do not
pass a value to that argument at the time of the function call.
Reason: The default arguments are optional during the function call. It overrides the
default value if we provide a value to the default arguments during function calls.
Ans:
8. Assertion (A): -Built in functions are predefined in the language that are used directly.
Reasoning(R): -print () and input () are built in functions.
Ans:
9. Assertion (A): - The default arguments can be skipped in the function call.
Reasoning (R): - The function argument will take the default values even if the values are
supplied in the function call.
Ans:
10. Assertion (A): The function definition calculate (a, b, c=1, d) will give error.
Reason (R): All the non-default arguments must precede the default arguments.
Ans:
11. Assertion (A): - To use a function from a particular module, we need to import the
module.
Reason (R): - import statement can be written anywhere in the program, before using a
function from that module.
Ans:
12. Assertion (A): Python standard library consists of number of modules.
Reason (R): A function in a module is used to simplify the code and avoids repetition.
Ans:
13. Assertion (A): For changes made to a variable defined within a function to be visible
outside the function, it should be declared as global.
Reason (R): Variables defined within a function are local to that function by default,
unless explicitly specified with the global keyword. Ans:

2
14. Assertion (A): A variable defined outside any function or any block is known as a
global variable.
Reason (R): A variable defined inside any function or a block is known as a local variable.
Ans:
15. Assertion (A): A function definition can have zero parameters/formal arguments.
Reason (R): Parenthesis are not mandatory to call a function with zero arguments.
Ans:
16. Assertion (A): Number of arguments passed to a function may not match the number
of parameters in the function definition.
Reason (R): Function parameters can have default values.
Ans:
17. Assertion (A): If the arguments in function call statement are provided in the format
parameter=argument, it is called keyword arguments.
Reason (R): During a function call, the argument list first contain keyword arguments(s)
followed by positional argument(s).
Ans:
18. Assertion (A): A function is block of organized and reusable code that is used to
perform a single, related action.
Reason (R): Function provides better modularity for your application and a high degree
of code reusability.
Ans:
19. Assertion (A): Functions in a program increases the modularity and readability of the
program.
Reason (R): Usage of functions increases the execution speed of the program.
Ans:
20. Assertion (A): Arguments are also called as actual arguments or actual parameters.
Reason (R): Parameters are also called as formal parameter or formal arguments.
Ans:

Common questions

Powered by AI

Variables defined outside any function or block are known as global variables and are visible throughout the program, including inside functions if redeclared as global. However, variables defined within a function are local to that function by default, and their scope does not extend outside the function unless they are explicitly declared as 'global' within that function. Changes to a local variable will not affect the variable outside unless it is specified with the 'global' keyword .

Default arguments in Python allow the function to be called with fewer arguments than it is defined with since they provide default values for parameters. If no value is passed for those parameters, the default value is used. The constraints are that non-default arguments must precede default arguments in a function definition. This means, all unnamed positional arguments must be supplied before any arguments that have default values .

Import statements can be written anywhere in a Python program, but it is generally best practice to place them at the top of the file, before any functions or executable code. This organization is crucial as it ensures that any necessary modules are available throughout the program's execution and also enhances the program's readability and structure .

Positional arguments are those that need to be passed in the correct order as specified in the function definition. Conversely, keyword arguments are passed by explicitly naming each parameter, regardless of their order. During a function call, if keyword arguments are used, they are placed before any positional arguments in the argument list. Keyword arguments allow more flexibility in function calls by ignoring the need for correct order while explicitly setting desired parameters .

If non-default arguments follow default arguments in a Python function definition, a syntax error occurs. This is problematic because Python cannot determine which arguments are intended to have default values when mixed improperly with positional arguments. Therefore, all positional arguments must be listed before any that have default values to avoid such ambiguity .

In Python, if a function doesn't have an explicit return statement, it returns 'None' by default. This means that any call to such a function will yield 'None' if not stated otherwise. Function design must consider this behavior to ensure that necessary values are passed back to the caller when required, especially in cases when output is expected .

Built-in functions in Python are functions that are predefined and readily available for use without needing explicit import statements. This functionality benefits programmers by providing immediate access to essential operations like data type conversions, input/output processing, and mathematical computations. Such predefined tools enhance development speed and reduce coding complexity .

Import statements in Python allow access to functions and classes defined in external modules, expanding the base functionality available in programs. By importing specific modules from the Python standard library or third-party libraries, a programmer can leverage pre-built solutions and complex functionalities without re-inventing the wheel. This aids in efficient code development and integrates powerful tools into the program .

Functions can lead to increased execution speed by modularizing tasks and optimizing code reusability, reducing redundancy and the computational load. However, this isn't inherently true for all cases; improper use of functions, such as excessive function calls or inefficient logic within a function, might degrade performance. Thus, the correlation of functions with improved execution speed relies on efficient function design and elimination of superfluous operations .

Python uses functions as blocks of organized, reusable code for performing specific, related actions. Functions enhance modularity and code reusability by allowing repeated code segments to be defined once within a function and called with different arguments as needed, without rewriting the code for each use. This structure helps simplify code and improves readability, making it easier to maintain and avoid redundancy .

You might also like