Functions allow programmers to organize and structure their code by splitting it into reusable blocks. There are two types of functions: built-in functions that are predefined in Python, and user-defined functions that programmers create. Functions make code easier to debug, test and maintain by dividing programs into separate, reusable parts. Functions can take arguments as input and return values. Function definitions do not alter the normal flow of a program's execution, but calling a function causes the program flow to jump to the function code and then return to pick up where it left off.
slide1: the content of functons
slide2: Introduction to function
slide3:function advantages
slide4 -5: types of functions
slide6: elements of user defined functions
This document discusses functions in Python. It begins by defining what a function is and provides examples of built-in functions and functions defined in modules. It then lists some advantages of using functions such as code reusability and readability. The document discusses the different types of functions - built-in functions, functions defined in modules, and user-defined functions. It provides examples of each type. The document also covers topics such as function parameters, return values, variable scope, lambda functions, and using functions from libraries.
This presentation covers a detailed overview of python advanced concepts. it covers the below aspects.
Comprehensions
Lambda with (map, filter and reduce)
Context managers
Iterator, Generators, Decorators
Python GIL and multiprocessing and multithreading
Python WSGI
Python Unittests
Python Session - 4
if
nested-if
if-else
elif (else if)
for loop (for iterating_var in sequence: )
while loop
break
continnue
pass
What is a function in Python?
Types of Functions
How to Define & Call Function
Scope and Lifetime of variables
lambda functions(anonymous functions)
Functions allow programmers to organize code into reusable units and divide large programs into smaller, more manageable parts. The document discusses key concepts related to functions in Python like defining and calling user-defined functions, passing arguments, scope, and recursion. It provides examples of different types of functions and how concepts like mutability impact parameter passing. Functions are a fundamental part of modular and readable program design.
The document provides an overview of functions in C++. It discusses the basic concepts of functions including declaring, defining, and calling functions. It covers function components like parameters and arguments. It explains passing parameters by value and reference. It also discusses different types of functions like built-in functions, user-defined functions, and functions with default arguments. Additionally, it covers concepts like scope of variables, return statement, recursion, and automatic vs static variables. The document is intended to teach the fundamentals of functions as building blocks of C++ programs.
The document provides an overview of functions in C++. It discusses the basic concepts of functions including declaring, defining, and calling functions. It covers different types of functions such as built-in functions, user-defined functions, and functions that return values. The key components of a function like the prototype, definition, parameters, arguments, and return statement are explained. It also describes different ways of passing parameters to functions, including call by value and call by reference. Functions allow breaking down programs into smaller, reusable components, making the code more readable, maintainable and reducing errors.
Functions are the building blocks where every program activity occurs. They are self-contained program segments that carry out some specific, well-defined task. Every C program must have a function c functions list. c functions multiple choice questions
slide1: the content of functons
slide2: Introduction to function
slide3:function advantages
slide4 -5: types of functions
slide6: elements of user defined functions
This document discusses functions in Python. It begins by defining what a function is and provides examples of built-in functions and functions defined in modules. It then lists some advantages of using functions such as code reusability and readability. The document discusses the different types of functions - built-in functions, functions defined in modules, and user-defined functions. It provides examples of each type. The document also covers topics such as function parameters, return values, variable scope, lambda functions, and using functions from libraries.
This presentation covers a detailed overview of python advanced concepts. it covers the below aspects.
Comprehensions
Lambda with (map, filter and reduce)
Context managers
Iterator, Generators, Decorators
Python GIL and multiprocessing and multithreading
Python WSGI
Python Unittests
Python Session - 4
if
nested-if
if-else
elif (else if)
for loop (for iterating_var in sequence: )
while loop
break
continnue
pass
What is a function in Python?
Types of Functions
How to Define & Call Function
Scope and Lifetime of variables
lambda functions(anonymous functions)
Functions allow programmers to organize code into reusable units and divide large programs into smaller, more manageable parts. The document discusses key concepts related to functions in Python like defining and calling user-defined functions, passing arguments, scope, and recursion. It provides examples of different types of functions and how concepts like mutability impact parameter passing. Functions are a fundamental part of modular and readable program design.
The document provides an overview of functions in C++. It discusses the basic concepts of functions including declaring, defining, and calling functions. It covers function components like parameters and arguments. It explains passing parameters by value and reference. It also discusses different types of functions like built-in functions, user-defined functions, and functions with default arguments. Additionally, it covers concepts like scope of variables, return statement, recursion, and automatic vs static variables. The document is intended to teach the fundamentals of functions as building blocks of C++ programs.
The document provides an overview of functions in C++. It discusses the basic concepts of functions including declaring, defining, and calling functions. It covers different types of functions such as built-in functions, user-defined functions, and functions that return values. The key components of a function like the prototype, definition, parameters, arguments, and return statement are explained. It also describes different ways of passing parameters to functions, including call by value and call by reference. Functions allow breaking down programs into smaller, reusable components, making the code more readable, maintainable and reducing errors.
Functions are the building blocks where every program activity occurs. They are self-contained program segments that carry out some specific, well-defined task. Every C program must have a function c functions list. c functions multiple choice questions
The document provides information on Python functions including defining, calling, passing arguments to, and scoping of functions. Some key points covered:
- Functions allow for modular and reusable code. User-defined functions in Python are defined using the def keyword.
- Functions can take arguments, have docstrings, and use return statements. Arguments are passed by reference in Python.
- Functions can be called by name and arguments passed positionally or by keyword. Default and variable arguments are also supported.
- Anonymous lambda functions can take arguments and return an expression.
- Variables in a function have local scope while global variables defined outside a function can be accessed anywhere. The global keyword is used to modify global variables from within a function
The document provides information on Python functions including defining, calling, passing arguments to, and scoping of functions. Some key points covered:
- Functions allow for modular and reusable code. User-defined functions in Python are defined using the def keyword.
- Functions can take arguments, have docstrings, and use return statements. Arguments are passed by reference in Python.
- Functions can be called by name and arguments passed positionally or by keyword. Default and variable arguments are also supported.
- Anonymous lambda functions can take arguments and return an expression.
- Variables in a function have local scope while global variables defined outside a function can be accessed anywhere. The global keyword is used to modify global variables from within a function
The document discusses functions in Python. It describes what functions are, different types of built-in functions like abs(), min(), max() etc. It also discusses commonly used modules like math, random, importing modules and functions within modules. It explains function definition, parameters, scope and lifetime of variables, return statement, default parameters, keyword arguments, variable length arguments and command line arguments.
The document discusses functions in the Python math module. It provides a list of common mathematical functions in the math module along with a brief description of what each function does, such as ceil(x) which returns the smallest integer greater than or equal to x, copysign(x, y) which returns x with the sign of y, and factorial(x) which returns the factorial of x. It also includes trigonometric functions like sin(x), cos(x), and tan(x), their inverse functions, and functions for exponentials, logarithms, and other common mathematical operations.
The document provides an overview of basic Python programming concepts including the structure of a Python program, data types, variables, operators, expressions, statements, functions, modules, and libraries. It discusses Python syntax elements like indentation, keywords, identifiers, literals, and escape sequences. It also covers basic Python programming concepts like input/output, operators, variables, and data types. The document is intended as an introductory guide to the basics of Python programming.
The document discusses the basics of functions in Python, including what a function is, the advantages of using functions, how to define and call functions, and how to use parameters, return values, global variables, default arguments, keyword arguments, and docstrings when working with functions. Key points covered include how functions allow code reuse and decomposition of complex problems, how to define a function using the def keyword, how to call a defined function by name, and how docstrings provide documentation for functions and other objects.
Functions allow programmers to organize code into reusable blocks. A function performs a specific task and can accept input parameters and return an output. Functions make code more modular and easier to maintain. Functions are defined with a name, parameters, and body. They can be called from other parts of the code to execute their task. Parameters allow functions to accept input values, while return values allow functions to return output to the calling code. Functions can be called by passing arguments by value or reference. The document provides examples and explanations of different types of functions in C++ like inline functions, functions with default arguments, and global vs local variables.
This document provides an outline and overview of functions in C++. It discusses:
- The definition of a function as a block of code that performs a specific task and can be called from other parts of the program.
- The standard library that is included in C++ and provides useful tools like containers, iterators, algorithms and more.
- The parts of a function definition including the return type, name, parameters, and body.
- How to declare functions, call functions by passing arguments, and how arguments are handled.
- Scope rules for local and global variables as they relate to functions.
This document discusses functions in C programming. It defines functions as blocks of code that perform specific tasks. It explains the key components of functions - function declaration, definition, and call. It provides examples of defining, declaring, and calling functions. It also discusses recursion, system-defined library functions, and user-defined functions.
The document introduces functions in C programming. It discusses defining and calling library functions and user-defined functions, passing arguments to functions, returning values from functions, and writing recursive functions. Functions allow breaking programs into modular and reusable units of code. Library functions perform common tasks like input/output and math operations. User-defined functions are created to perform specific tasks. Information is passed between functions via arguments and return values.
The document discusses functions in Python. It defines a function as a block of code that performs a specific task and only runs when called. Functions can take parameters as input and return values. Some key points covered include:
- User-defined functions can be created in Python in addition to built-in functions.
- Functions make code reusable, readable, and modular. They allow for easier testing and maintenance of code.
- Variables can have local, global, or non-local scope depending on where they are used.
- Functions can take positional/required arguments, keyword arguments, default arguments, and variable length arguments.
- Objects passed to functions can be mutable like lists, causing pass by
Storage class determines the accessibility and lifetime of a variable. The main storage classes in C++ are automatic, external, static, and register. Automatic variables are local to a function and are created and destroyed each time the function is called. External variables have global scope and persist for the lifetime of the program. Static variables also have local scope but retain their value between function calls.
Slides for Lecture 1 of the course: Introduction to Programming with Python offered at ICCBS.
It covers the following topics:
1.) Variables, Statements and Expressions
2.) Functions
3.) Flow Control
The document discusses functions in Python. It defines a function as a block of code that performs a specific task and only runs when called. There are three types of functions: built-in functions, functions defined in modules, and user-defined functions. Functions can take parameters and return values. Variables used in functions can have local, global, or nonlocal scope. Functions allow for code reusability and modularity.
The document discusses functions in Python. It defines a function as a block of code that performs a specific task and can be called when needed. Functions make code reusable, readable, and help divide programs into modular pieces. The document covers built-in functions, user-defined functions, passing arguments to functions, scope of variables, mutable and immutable objects, and functions available in Python libraries like math and string functions.
This document discusses functions in Python. It begins by defining what a function is - a block of code that performs a specific task and only runs when called. User-defined functions can be created in Python. The document outlines the advantages of using functions such as code reusability and readability. It provides an example of defining and calling a simple function. It also discusses variable scope in functions, including local, global, and nonlocal variables. Finally, it covers passing different data types like numbers, lists, dictionaries and strings to functions.
This document discusses functions in Python. It begins by defining what a function is - a block of code that performs a specific task and only runs when called. User-defined functions can be created in Python. The document outlines the advantages of using functions such as code reusability and readability. It provides an example of defining and calling a simple function. It discusses variable scope within functions and different types of arguments that can be passed to functions. The document also covers passing different data types like lists, dictionaries and strings to functions. Finally, it discusses using functions from library modules like math and string functions.
The document discusses functions in C++. It begins by outlining key topics about functions that will be covered, such as function definitions, standard library functions, and function calls. It then provides details on defining and calling functions, including specifying return types, parameters, function prototypes, scope rules, and passing arguments by value or reference. The document also discusses local and global variables, function errors, and the differences between calling functions by value or reference.
The document provides information on Python functions including defining, calling, passing arguments to, and scoping of functions. Some key points covered:
- Functions allow for modular and reusable code. User-defined functions in Python are defined using the def keyword.
- Functions can take arguments, have docstrings, and use return statements. Arguments are passed by reference in Python.
- Functions can be called by name and arguments passed positionally or by keyword. Default and variable arguments are also supported.
- Anonymous lambda functions can take arguments and return an expression.
- Variables in a function have local scope while global variables defined outside a function can be accessed anywhere. The global keyword is used to modify global variables from within a function
The document provides information on Python functions including defining, calling, passing arguments to, and scoping of functions. Some key points covered:
- Functions allow for modular and reusable code. User-defined functions in Python are defined using the def keyword.
- Functions can take arguments, have docstrings, and use return statements. Arguments are passed by reference in Python.
- Functions can be called by name and arguments passed positionally or by keyword. Default and variable arguments are also supported.
- Anonymous lambda functions can take arguments and return an expression.
- Variables in a function have local scope while global variables defined outside a function can be accessed anywhere. The global keyword is used to modify global variables from within a function
The document discusses functions in Python. It describes what functions are, different types of built-in functions like abs(), min(), max() etc. It also discusses commonly used modules like math, random, importing modules and functions within modules. It explains function definition, parameters, scope and lifetime of variables, return statement, default parameters, keyword arguments, variable length arguments and command line arguments.
The document discusses functions in the Python math module. It provides a list of common mathematical functions in the math module along with a brief description of what each function does, such as ceil(x) which returns the smallest integer greater than or equal to x, copysign(x, y) which returns x with the sign of y, and factorial(x) which returns the factorial of x. It also includes trigonometric functions like sin(x), cos(x), and tan(x), their inverse functions, and functions for exponentials, logarithms, and other common mathematical operations.
The document provides an overview of basic Python programming concepts including the structure of a Python program, data types, variables, operators, expressions, statements, functions, modules, and libraries. It discusses Python syntax elements like indentation, keywords, identifiers, literals, and escape sequences. It also covers basic Python programming concepts like input/output, operators, variables, and data types. The document is intended as an introductory guide to the basics of Python programming.
The document discusses the basics of functions in Python, including what a function is, the advantages of using functions, how to define and call functions, and how to use parameters, return values, global variables, default arguments, keyword arguments, and docstrings when working with functions. Key points covered include how functions allow code reuse and decomposition of complex problems, how to define a function using the def keyword, how to call a defined function by name, and how docstrings provide documentation for functions and other objects.
Functions allow programmers to organize code into reusable blocks. A function performs a specific task and can accept input parameters and return an output. Functions make code more modular and easier to maintain. Functions are defined with a name, parameters, and body. They can be called from other parts of the code to execute their task. Parameters allow functions to accept input values, while return values allow functions to return output to the calling code. Functions can be called by passing arguments by value or reference. The document provides examples and explanations of different types of functions in C++ like inline functions, functions with default arguments, and global vs local variables.
This document provides an outline and overview of functions in C++. It discusses:
- The definition of a function as a block of code that performs a specific task and can be called from other parts of the program.
- The standard library that is included in C++ and provides useful tools like containers, iterators, algorithms and more.
- The parts of a function definition including the return type, name, parameters, and body.
- How to declare functions, call functions by passing arguments, and how arguments are handled.
- Scope rules for local and global variables as they relate to functions.
This document discusses functions in C programming. It defines functions as blocks of code that perform specific tasks. It explains the key components of functions - function declaration, definition, and call. It provides examples of defining, declaring, and calling functions. It also discusses recursion, system-defined library functions, and user-defined functions.
The document introduces functions in C programming. It discusses defining and calling library functions and user-defined functions, passing arguments to functions, returning values from functions, and writing recursive functions. Functions allow breaking programs into modular and reusable units of code. Library functions perform common tasks like input/output and math operations. User-defined functions are created to perform specific tasks. Information is passed between functions via arguments and return values.
The document discusses functions in Python. It defines a function as a block of code that performs a specific task and only runs when called. Functions can take parameters as input and return values. Some key points covered include:
- User-defined functions can be created in Python in addition to built-in functions.
- Functions make code reusable, readable, and modular. They allow for easier testing and maintenance of code.
- Variables can have local, global, or non-local scope depending on where they are used.
- Functions can take positional/required arguments, keyword arguments, default arguments, and variable length arguments.
- Objects passed to functions can be mutable like lists, causing pass by
Storage class determines the accessibility and lifetime of a variable. The main storage classes in C++ are automatic, external, static, and register. Automatic variables are local to a function and are created and destroyed each time the function is called. External variables have global scope and persist for the lifetime of the program. Static variables also have local scope but retain their value between function calls.
Slides for Lecture 1 of the course: Introduction to Programming with Python offered at ICCBS.
It covers the following topics:
1.) Variables, Statements and Expressions
2.) Functions
3.) Flow Control
The document discusses functions in Python. It defines a function as a block of code that performs a specific task and only runs when called. There are three types of functions: built-in functions, functions defined in modules, and user-defined functions. Functions can take parameters and return values. Variables used in functions can have local, global, or nonlocal scope. Functions allow for code reusability and modularity.
The document discusses functions in Python. It defines a function as a block of code that performs a specific task and can be called when needed. Functions make code reusable, readable, and help divide programs into modular pieces. The document covers built-in functions, user-defined functions, passing arguments to functions, scope of variables, mutable and immutable objects, and functions available in Python libraries like math and string functions.
This document discusses functions in Python. It begins by defining what a function is - a block of code that performs a specific task and only runs when called. User-defined functions can be created in Python. The document outlines the advantages of using functions such as code reusability and readability. It provides an example of defining and calling a simple function. It also discusses variable scope in functions, including local, global, and nonlocal variables. Finally, it covers passing different data types like numbers, lists, dictionaries and strings to functions.
This document discusses functions in Python. It begins by defining what a function is - a block of code that performs a specific task and only runs when called. User-defined functions can be created in Python. The document outlines the advantages of using functions such as code reusability and readability. It provides an example of defining and calling a simple function. It discusses variable scope within functions and different types of arguments that can be passed to functions. The document also covers passing different data types like lists, dictionaries and strings to functions. Finally, it discusses using functions from library modules like math and string functions.
The document discusses functions in C++. It begins by outlining key topics about functions that will be covered, such as function definitions, standard library functions, and function calls. It then provides details on defining and calling functions, including specifying return types, parameters, function prototypes, scope rules, and passing arguments by value or reference. The document also discusses local and global variables, function errors, and the differences between calling functions by value or reference.
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Dr. Vinod Kumar Kanvaria
Exploiting Artificial Intelligence for Empowering Researchers and Faculty,
International FDP on Fundamentals of Research in Social Sciences
at Integral University, Lucknow, 06.06.2024
By Dr. Vinod Kumar Kanvaria
The simplified electron and muon model, Oscillating Spacetime: The Foundation...RitikBhardwaj56
Discover the Simplified Electron and Muon Model: A New Wave-Based Approach to Understanding Particles delves into a groundbreaking theory that presents electrons and muons as rotating soliton waves within oscillating spacetime. Geared towards students, researchers, and science buffs, this book breaks down complex ideas into simple explanations. It covers topics such as electron waves, temporal dynamics, and the implications of this model on particle physics. With clear illustrations and easy-to-follow explanations, readers will gain a new outlook on the universe's fundamental nature.
Strategies for Effective Upskilling is a presentation by Chinwendu Peace in a Your Skill Boost Masterclass organisation by the Excellence Foundation for South Sudan on 08th and 09th June 2024 from 1 PM to 3 PM on each day.
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPRAHUL
This Dissertation explores the particular circumstances of Mirzapur, a region located in the
core of India. Mirzapur, with its varied terrains and abundant biodiversity, offers an optimal
environment for investigating the changes in vegetation cover dynamics. Our study utilizes
advanced technologies such as GIS (Geographic Information Systems) and Remote sensing to
analyze the transformations that have taken place over the course of a decade.
The complex relationship between human activities and the environment has been the focus
of extensive research and worry. As the global community grapples with swift urbanization,
population expansion, and economic progress, the effects on natural ecosystems are becoming
more evident. A crucial element of this impact is the alteration of vegetation cover, which plays a
significant role in maintaining the ecological equilibrium of our planet.Land serves as the foundation for all human activities and provides the necessary materials for
these activities. As the most crucial natural resource, its utilization by humans results in different
'Land uses,' which are determined by both human activities and the physical characteristics of the
land.
The utilization of land is impacted by human needs and environmental factors. In countries
like India, rapid population growth and the emphasis on extensive resource exploitation can lead
to significant land degradation, adversely affecting the region's land cover.
Therefore, human intervention has significantly influenced land use patterns over many
centuries, evolving its structure over time and space. In the present era, these changes have
accelerated due to factors such as agriculture and urbanization. Information regarding land use and
cover is essential for various planning and management tasks related to the Earth's surface,
providing crucial environmental data for scientific, resource management, policy purposes, and
diverse human activities.
Accurate understanding of land use and cover is imperative for the development planning
of any area. Consequently, a wide range of professionals, including earth system scientists, land
and water managers, and urban planners, are interested in obtaining data on land use and cover
changes, conversion trends, and other related patterns. The spatial dimensions of land use and
cover support policymakers and scientists in making well-informed decisions, as alterations in
these patterns indicate shifts in economic and social conditions. Monitoring such changes with the
help of Advanced technologies like Remote Sensing and Geographic Information Systems is
crucial for coordinated efforts across different administrative levels. Advanced technologies like
Remote Sensing and Geographic Information Systems
9
Changes in vegetation cover refer to variations in the distribution, composition, and overall
structure of plant communities across different temporal and spatial scales. These changes can
occur natural.
বাংলাদেশের অর্থনৈতিক সমীক্ষা ২০২৪ [Bangladesh Economic Review 2024 Bangla.pdf] কম্পিউটার , ট্যাব ও স্মার্ট ফোন ভার্সন সহ সম্পূর্ণ বাংলা ই-বুক বা pdf বই " সুচিপত্র ...বুকমার্ক মেনু 🔖 ও হাইপার লিংক মেনু 📝👆 যুক্ত ..
আমাদের সবার জন্য খুব খুব গুরুত্বপূর্ণ একটি বই ..বিসিএস, ব্যাংক, ইউনিভার্সিটি ভর্তি ও যে কোন প্রতিযোগিতা মূলক পরীক্ষার জন্য এর খুব ইম্পরট্যান্ট একটি বিষয় ...তাছাড়া বাংলাদেশের সাম্প্রতিক যে কোন ডাটা বা তথ্য এই বইতে পাবেন ...
তাই একজন নাগরিক হিসাবে এই তথ্য গুলো আপনার জানা প্রয়োজন ...।
বিসিএস ও ব্যাংক এর লিখিত পরীক্ষা ...+এছাড়া মাধ্যমিক ও উচ্চমাধ্যমিকের স্টুডেন্টদের জন্য অনেক কাজে আসবে ...
Executive Directors Chat Leveraging AI for Diversity, Equity, and InclusionTechSoup
Let’s explore the intersection of technology and equity in the final session of our DEI series. Discover how AI tools, like ChatGPT, can be used to support and enhance your nonprofit's DEI initiatives. Participants will gain insights into practical AI applications and get tips for leveraging technology to advance their DEI goals.
How to Setup Warehouse & Location in Odoo 17 InventoryCeline George
In this slide, we'll explore how to set up warehouses and locations in Odoo 17 Inventory. This will help us manage our stock effectively, track inventory levels, and streamline warehouse operations.
Walmart Business+ and Spark Good for Nonprofits.pdfTechSoup
"Learn about all the ways Walmart supports nonprofit organizations.
You will hear from Liz Willett, the Head of Nonprofits, and hear about what Walmart is doing to help nonprofits, including Walmart Business and Spark Good. Walmart Business+ is a new offer for nonprofits that offers discounts and also streamlines nonprofits order and expense tracking, saving time and money.
The webinar may also give some examples on how nonprofits can best leverage Walmart Business+.
The event will cover the following::
Walmart Business + (https://business.walmart.com/plus) is a new shopping experience for nonprofits, schools, and local business customers that connects an exclusive online shopping experience to stores. Benefits include free delivery and shipping, a 'Spend Analytics” feature, special discounts, deals and tax-exempt shopping.
Special TechSoup offer for a free 180 days membership, and up to $150 in discounts on eligible orders.
Spark Good (walmart.com/sparkgood) is a charitable platform that enables nonprofits to receive donations directly from customers and associates.
Answers about how you can do more with Walmart!"
How to Add Chatter in the odoo 17 ERP ModuleCeline George
In Odoo, the chatter is like a chat tool that helps you work together on records. You can leave notes and track things, making it easier to talk with your team and partners. Inside chatter, all communication history, activity, and changes will be displayed.
2. FUNCTIONS
Function is a sub program which consists of set of instructions used to perform a specific task.
A large program is divided into basic building blocks called function
3. Need For Function
When the program is too complex and large they are divided into parts. Each part is separately coded
and combined into single program. Each subprogram is called as function.
Debugging, Testing and maintenance becomes easy when the program is divided into subprograms.
Functions are used to avoid rewriting same code again and again in a program.
Function provides code re-usability
The length of the program is reduced.
4. Types of Functions
Functions are classified into 2-types
Built-in Functions (or) Pre-defined Functions
User Defined Functions
5. Built in functions
Built in functions are the functions that are already created and stored in python
These built in functions are always available for usage and accessed by a programmer. It cannot
be modified
Ex: Max,min,len,range,input…etc
6. User Defined Functions
User defined functions are the functions that programmers create for their requirement and use.
These functions can then be combined to form module which can be used in other programs by
importing them
Advantages of user defined functions:
Programmers working on large project can divide the workload by making different functions.
If repeated code occurs in a program, function can be used to include those codes and execute when
needed by calling that function
7. Function definition
def keyword is used to define a function.
Give the function name after def keyword followed by parentheses in which arguments are given.
End with colon (:)
Inside the function add the program statements to be executed
End with or without return statemen
Syntax:
def fun_name(Parameter1,Parameter2…Parameter n):
statement1
statement2…
statement n
return[expression]
9. Function Calling
Once we have defined a function, we can call it from another function, program or even the Python
prompt.
To call a function we simply type the function name with appropriatearguments.
Example:
x=5
y=4
my_add(x,y)
10. Flow of Execution
The order in which statements are executed is called the flow of execution
Execution always begins at the first statement of the program.
Statements are executed one at a time, in order, from top to bottom.
Function definitions do not alter the flow of execution of the program, but remember that
statements inside the function are not executed until the function is called.
Function calls are like a bypass in the flow of execution. Instead of going to the next statement, the
flow jumps to the first line of the called function, executes all the statements there, and then comes
back to pick up where it left off.
11. Function Prototypes
Function without arguments and without return type
Function with arguments and without return type
Function without arguments and with return type
Function with arguments and with return type
12. Function Arguments
You can call a function by using the following types of formal arguments −
Required arguments
Keyword arguments
Default arguments
Variable-length arguments
13. Function without arguments and without
return type
In this type no argument is passed through the function call and no output is return to main function
The sub function will read the input values perform the operation and print the result in the same
block
14. Error and Exception
An exception is an event, which occurs during the execution of a program that disrupts the normal
flow of the program's instructions.
When a Python script raises an exception, it must either handle the exception immediately
otherwise it terminates and quits
15. Python Built-in Exceptions
Illegal operations can raise exceptions. There are plenty of built-in exceptions in Python that are
raised when corresponding errors occur.
AttributeError Raised when attribute assignment or reference fails.
EOFError : Raised when the input() functions hits end-of-file condition.
FloatingPointError : Raised when a floating point operation fails.
GeneratorExit : Raise when a generator's close() method is called.
OverflowError : Raised when result of an arithmetic operation is too large to be represented.
ReferenceError : Raised when a weak reference proxy is used to access a garbage collected referent.
RuntimeError : Raised when an error does not fall under any other category.
16. Exception Handling
To handle the exception, python use below keywords
try
except
else
finally
raise
17. The try: block contains one or more statements which are likely to encounter an exception. If the
statements in this block are executed without an exception, the subsequent except: block is
skipped.
Except : this code is only executed if an exception occured in the try block. The except block is
required with a try block, even if it contains only the pass statement.
else: Code in the else block is only executed if no exceptions were raised in the try block.
finally: The code in the finally block is always executed, regardless of if a an exception was raised
or not.
18. Catching Exceptions in Python
try:
x=int(input(“Enter value of x:”))
y=int(input(“Enter value of y:”))
z=x/y
print(z)
except ZeroDivisionError:
print('Divided by zero')
print('Should reach here')
19. Catching Generic Exceptions in Python
try:
x=int(input(“Enter value of x:”))
y=int(input(“Enter value of y:”))
z=x/y
print(z)
except :
print('Divided by zero')
print('Should reach here')
20. try else
try:
x = 1
except:
print('Failed to set x')
else:
print('No exception occurred')
finally:
print('We always do this')
21. raise
x = 110
try:
if x < 0:
raise Exception("Sorry, no numbers below zero")
except Exception as ex:
print(ex.args)
else:
print("value of X:",x)
22. Comprehensions in Python
Comprehensions in Python provide us with a short and concise way to construct new sequences
(such as lists, set, dictionary etc.)
using sequences which have been already defined.
Python supports the following 4 types of comprehensions
List Comprehensions
Dictionary Comprehensions
Set Comprehensions
Generator Comprehensions
23. List Comprehensions
List Comprehensions provide an stylish way to create new lists
Syntax
output_list = [output_exp for var in input_list if (var satisfies this condition)]
24. input_list = [1, 2, 3, 4, 4, 5, 6, 7, 7]
output_list = []
for var in input_list:
if var % 2 == 0:
output_list.append(var)
print("Output List using for loop:", output_list)
25. input_list = [1, 2, 3, 4, 4, 5, 6, 7, 7]
list_using_comp = [var for var in input_list if var % 2 == 0]
print("Output List using list comprehensions:", list_using_comp)
26. list_using_comp = [var**2 for var in range(1, 10)]
print("Output List using list comprehension:", list_using_comp)
27. Dictionary Comprehensions
we can also create a dictionary using dictionary comprehensions
output_dict = {key:value for (key, value) in iterable if (key, value satisfy this condition)}
28. input_list = [1, 2, 3, 4, 5, 6, 7]
output_dict = {}
for var in input_list:
if var % 2 != 0:
output_dict[var] = var**3
print("Output Dictionary using for loop:", output_dict )
29. input_list = [1,2,3,4,5,6,7]
dict_using_comp = {var:var ** 3 for var in input_list if var % 2 != 0}
print("Output Dictionary using dictionary comprehensions:", dict_using_comp)
30. state = ['Gujarat', 'Maharashtra', 'Rajasthan']
capital = ['Gandhinagar', 'Mumbai', 'Jaipur']
output_dict = {}
for (key, value) in zip(state, capital):
output_dict[key] = value
print("Output Dictionary using for loop:", output_dict)
Note : Python zip() method takes iterable or containers and returns a single iterator object, having
mapped values from all the containers
31. state = ['Gujarat', 'Maharashtra', 'Rajasthan']
capital = ['Gandhinagar', 'Mumbai', 'Jaipur']
dict_using_comp = {key:value for (key, value) in zip(state, capital)}
print("Output Dictionary using dictionary comprehensions:", dict_using_comp)
32. Set Comprehensions
Set comprehensions are similar to list comprehensions.
The only difference between them is that set comprehensions use curly brackets { }
33. input_list = [1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 7]
output_set = set()
for var in input_list:
if var % 2 == 0:
output_set.add(var)
print("Output Set using for loop:", output_set)
34. input_list = [1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 7]
set_using_comp = {var for var in input_list if var % 2 == 0}
print("Output Set using set comprehensions:", set_using_comp)
35. Generator Comprehensions
Generator Comprehensions are very similar to list comprehensions.
One difference between them is that generator comprehensions use circular brackets whereas list
comprehensions use square brackets
The major difference between them is that generators don’t allocate memory for the whole list
36. input_list = [1, 2, 3, 4, 4, 5, 6, 7, 7]
output_gen = (var for var in input_list if var % 2 == 0)
print("Output values using generator comprehensions:", end = ' ')
for var in output_gen:
print(var, end = ' ')
38. Iteration is the idea of repeating some process over a sequence of items. In Python, iteration is
usually related to the for loop.
An iterable is an object that supports iteration.
39. Eager evaluation
As soon as call fun(), The
Expression is evaluated and return
resulted value
40. Lazy evaluation
The Main idea behind lazy evaluation is
to evaluate expression only when
needed
41. Iterator
An iterator is an object which contains a countable number of values and it is used to iterate over
iterable objects like list, tuples, sets, etc
It follows lazy evaluation where the evaluation of the expression will be on hold and stored in the
memory until the item is called specifically which helps us to avoid repeated evaluation
Using an iterator-
iter() keyword is used to create an iterator containing an iterable object.
next() keyword is used to call the next element in the iterable object.
42.
43. Generators
Generators simplifies creation of iterators.
A generator is a function that produces a sequence of results instead of a single value.
Generators are iterables
44.
45. Sorting
Python sorted() function returns a sorted list from the iterable object.
Sorted() sorts any sequence (list, tuple) and always returns a list with the elements in a sorted
manner, without modifying the original sequence.
Syntax: sorted(iterable, key, reverse)
Iterable : sequence (list, tuple, string) or collection (dictionary, set) or any other iterator that needs to be
sorted.
Key(optional) : A function that would server as a key or a basis of sort comparison.
Reverse(optional) : If set true, then the iterable would be sorted in reverse (descending) order, by default it
is set as false.
X=sorted(list)
46. Python sorted() key
sorted() function has an optional parameter called ‘key’ which takes a function as its value
For example, if we pass a list of strings in sorted(), it gets sorted alphabetically. But if we specify
key = len, i.e. give len function as key, then the strings would be passed to len, and the value it
returns, i.e. the length of strings will be sorted
47. L = ["cccc", "b", "dd", "aaa"]
print("Normal sort :", sorted(L))
print("Sort with len :", sorted(L, key=len))
50. Python can generate such random numbers by using the random module
function random(), which generates a random float number between 0.0 and 1.0
Methods:
Random() :which generates a random float number between 0.0 and 1.0
Choice(list/tuple) : The choice() is an inbuilt function in the Python programming language that returns a
random item from a list, tuple, or string
randrange(beg, end, step) : function that can generate random numbers from a specified range
randint(beg,end) : method generates a integer between a given range of numbers
sample(range,no.of_numbers) : to directly generate a list of random numbers
Ex: random.sample(range(10,50),5)
51. Seed(int): The seed function is used to save the state of a random function so that it can generate
some random numbers on multiple executions of the code on the same machine or on different
machines (for a specific seed value)
shuffle() Takes a sequence and returns the sequence in a random order
random.shuffle(mylist)
52. Regular Expressions
A Regular Expressions (RegEx) is a special sequence of characters that uses a search pattern to
find a string or set of strings.
It can detect the presence or absence of a text by matching it with a particular pattern, and also
can split a pattern into one or more sub-patterns.
Python provides a re module that supports the use of regex in Python
53. MetaCharacters
Metacharacters Description
[ ] Represent a character class
^ Matches the beginning
$ Matches the end
. Matches any character except newline
| Means OR (Matches with any of the characters separated by it.
? Matches zero or one occurrence
* Any number of occurrences (including 0 occurrences)
+ One or more occurrences
54.
55. Special Sequences
Special sequences do not match for the actual character in the string instead it tells the specific
location in the search string where the match must occur
56. Special Sequence Description
d Matches any decimal digit, this is equivalent to the set class [0-9]
D Matches any non-digit character, this is equivalent to the set class [^0-9]
w Matches any alphanumeric character, this is equivalent to the class [a-zA-Z0-9_].
W Matches any non-alphanumeric character.
57. findall()
Return all non-overlapping
matches of pattern in string,
as a list of strings
58.
59. compile()
Regular expressions are compiled
into pattern objects, which have
methods for various operations
such as searching for pattern
matches or performing string
substitutions
60.
61. split()
Split string by the occurrences of a character or a pattern
re.split(pattern, string, maxsplit=0, flags=0)
The First parameter, pattern denotes the regular expression
string is the given string in which pattern will be searched for and in which splitting occurs
maxsplit if not provided is considered to be zero ‘0’, and if any nonzero value is provided,
then at most that many splits occur.
If maxsplit = 1, then the string will split once only, resulting in a list of length 2.
The flags are very useful and can help to shorten code, they are not necessary parameters,
eg: flags = re.IGNORECASE, in this split, the case, i.e. the lowercase or the uppercase will
be ignored
62.
63. sub()
The ‘sub’ in the function stands for SubString, a certain regular expression pattern is searched in
the given string and upon finding the substring pattern is replaced by repl, count checks and
maintains the number of times this occurs
Syntax:
re.sub(pattern, repl, string, count=0, flags=0)
66. object-oriented Programming (OOPs) is a programming model that uses objects and classes in
programming.
It aims to implement real-world entities like inheritance, polymorphisms, encapsulation
The main concept of OOPs is to bind the data and the functions that work on that together as a
single unit so that no other part of the code can access this data
67. Concepts of Object-Oriented Programming
Class
Objects
Polymorphism
Encapsulation
Inheritance
Data Abstraction
68. Class
A class is a collection of objects
It is a logical entity that contains some attributes and methods
Syntax:
class ClassName:
# Statement-1
.
.
.
# Statement-N
Classes are created by keyword class.
Attributes are the variables that belong to a class.
Attributes are always public and can be accessed using the dot (.) operator
70. Objects
The object is an entity that has a state and behavior associated with it
An object consists of :
State: It is represented by the attributes of an object. It also reflects the properties of an object.
Behavior: It is represented by the methods of an object. It also reflects the response of an object to other
objects.
Identity: It gives a unique name to an object and enables one object to interact with other objects.
Syntax:
Obj = Student()
71. __init__ method
The __init__ method is similar to constructors in C++ and Java. It is run as soon as an object of a
class is instantiated
72. Inheritance
Inheritance is the capability of one class to derive or inherit the properties from another class
The existing class is called base class or parent class or super class
Newly created class is called derived class or child class or sub class
Types of inheritances
Single Inheritance
Multilevel Inheritance
Hierarchical Inheritance
Multiple Inheritance
73. Polymorphism
Polymorphism is an object-oriented programming concept that allows us to perform a single action
in different ways
74. Encapsulation
Encapsulation is one of the fundamental concepts in object-oriented programming (OOP).
It describes the idea of wrapping data and the methods that work on data within one unit
75. enumerate
Enumerate() method adds a counter to an iterable and returns it in a form of enumerating object.
This enumerated object can then be used directly for loops or converted into a list of tuples using
the list() method.
Syntax:
enumerate(iterable, start=0)
Parameters:
Iterable: any object that supports iteration
Start: the index value from which the counter is to be started, by default it is 0