0% found this document useful (0 votes)
10 views28 pages

Python Functions and Variable Scope

Lecture 5 covers various Python programming concepts including local and global variables, keyword arguments, string formatting, list comprehension, higher order functions, lambda functions, 2D arrays, and file handling with JSON. Local variables are defined within functions and have a limited scope, while global variables are accessible throughout the program. The lecture also emphasizes the use of the global keyword to modify global variables within functions.

Uploaded by

Eman Elsheikh
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)
10 views28 pages

Python Functions and Variable Scope

Lecture 5 covers various Python programming concepts including local and global variables, keyword arguments, string formatting, list comprehension, higher order functions, lambda functions, 2D arrays, and file handling with JSON. Local variables are defined within functions and have a limited scope, while global variables are accessible throughout the program. The lecture also emphasizes the use of the global keyword to modify global variables within functions.

Uploaded by

Eman Elsheikh
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

PYTHON

Lecture 5
functions
outlines
• Pass
• Global/local variables
• Keyword arguments
• String formatting
• List comprehension
• Higher order functions
• Lambda
• 2D arrays
• Files and json
Local Variables

Definition: Variables declared inside a function are local to


that function.
Scope: Accessible only within the function where they are
defined.
Global Variables

Definition: Variables declared outside of any function or block


are global variables.
Scope: Accessible throughout the entire program, including
inside functions
Modifying Global Variables

To modify a global variable inside a function, the global keyword


must be used. Without it, Python will treat it as a local variable by
default.
[Link](reverse=True)
Higher order functions

Higher order Callback


Js not python
Anonymous function, lambda
Creating a 2D Array

You might also like