- What is Python?
- How to Install Python?
- Python Variables and Operators
- Python Loops
- Python Functions
- Python Files
- Python Errors and Exceptions
- Python Packages
- Python Classes and Objects
- Python Strings
- PostgreSQL Data Types
- Python Generators and Decorators
- Python Dictionary
- Python Date and Time
- Python List and Tuples
- Python Multithreading and Synchronization
- Python Modules
- What is Python bytecode?
- Python Regular Expressions
Interview Questions & Answers
The function is a structure of a program which supports the re-usability. These functions enable suitable modularity for the software in an individual action. Python supports built-in functions like Print (). It enables the clients to generate the function of our own. These are called user-defined functions.
Rules for representing a function
The function name must begin with a def keyword pursue by a function name and parenthesis.
All the arguments and input parameters must be located inside the parenthesis.
The functional program within the function must begin with the colon :
It can exit the function, and we can utilize the return (this can assign object return to the caller)
sum (10, 20)
Function calling (or) function invoking
The definition of the function would provide the name and define the values/ parameter that should be contained in a function. Once the function has provided the basic mechanism, it can be implemented by calling from the other functions. Besides, this can also be known as from the python prompt.
Def function_name ():
Def first ():
print (‘this is the first function’)
These are the values passed in a function. There are the following types of arguments are as follows:
These arguments support a default value if nothing is kept in the function call. These have to be represented in the function definition.
These arguments are associated with the calls. Due to parameter, name-caller recognize the arguments. This enables skipping arguments.
These are those arguments that are passed to the function in the right series as per their situations.
In some methods, we require to write functions that accept more arguments than they specified. These arguments are known as these arguments as a variable-length argument.
Scope of the variable
The variables declare this have multiple scopes.
The variables that can be approached in a function, where it is declared. It cannot be approached outside the function.
a = ‘We are the local variable’
We are the local variable
This is unlike the local variable. This can be accessed worldwide. The variables that are declared ones can be approached a few functions.
s= ‘We’ are the local function. We override the global function
a= ‘We are the local function, we cannot access the outside the function f
# Global scope
b= “Since, We are the global function, print S is called before the function, and first expected”
a= ‘i love python’
Since, We are the global function, print S is called before the function, and first expected we are the local function. We overrided the global function
We are the local function, and we cannot access the outside the function f
I love python
What are Doc strings?
It supports an appropriate method of relating records, with python modules, classes, functions, and methods. doc_ strings can be approached by __doc__ attribute.
How to define a docstring?
The docstring line must begin with a capital letter. The first line must be a short definition, and we must not write the object name.
def my_function ():
“””Illustrate docstrings and does nothing really.”””
print (“Using __doc__:”)
Demonstrate docstrings and does nothing really.
There are two most general methods of passing a parameter to a function.
Call by Value
This method is used in C, C++ or Java but not utilized in Python. In call by value, the values of actual arguments are replica to function’s formal arguments, and both types of arguments are saved in individual memory locations.
Call by Reference
The functions are known by reference in Python, which defines all the modification implemented to the inside the function reflected in an actual argument.
The recursive function is a function that calls itself in its definition. For instance the mathematical function, factorial, represented by factorial(n) = n*(n-1)*(n-2)*…*3*2*1. can be defined as:
#n here should be an integer
if n == 0:
Enroll Yourself : Python Training In Delhi