-
Notifications
You must be signed in to change notification settings - Fork 3
Clarifying some basics
nonlocal:
The nonlocal keyword adds a scope override to the inner scope.
you must use nonlocal in a nested function.
def counter():
num = 0
def incrementer():
nonlocal num
# without nonlocal keyword will not be able to access outside variable
num += 1
return num
return incrementer
local:
variables inside functions are considered local if and only if they appear in the left side of an assignment
statement. function can read outside variable inside function.
global:
To access variables outside the function, we have to declare global variable name inside function where we want to change its value .
In Python 3.x, the print function has an optional end parameter that is what it prints at the end of the given string. By default it's a newline character, so equivalent to this:
print("Hello, ", end="\n")
print("World!")
Hello,
World!
print("Hello, ", end="")
print("World!")
Hello, World!
Keep Learning. Never Settle! 😊
- Home
- 1.Introduction To Python
- 2. DataTypes
- 3. Strings and Slicing of collection
- 4.If else & Loops
- 5. Break, continue, pass
- 6. Functions
- 7. Modules
- 8. Clarifying basics
- 9. File Handling
- 10. Exception Handling
- 11. Dig into Collections
- 12. Iterators, Generators and list comprehension
- 13. lambdas , map, filter and other concepts
- 14. args, kwargs an default parameters
- 15. Functional Programming
- 16. OOPs