Python Scripting - Week 6 Flashcards
What is namespace in python ?
It means scope of an variable where it belongs to ?
How many name spaces in python ?
LEGB
Local - Local Scope
Enclosed - Function within Function,Nested Function
Global - A variable which have scope everywhere.
Built-ins - Builtin Functions
It corresponds to function
How to print python builtins ?
dir(__builtins__)
Builtins are loaded on startup bydefault,when python program starts
How to get help of builtin ?
help(ArithmeticError)
How to get type of builtin ?
typer(ArithmeticError)
How to print globals ?
globals()
How to print the all globals in table format ?
whos
In which namespace should every varaible is stored ?
Every variable is stored in the globals
How python searches for variable, what is rthe thumb rule ?
Python follows LEGB rule ?
Local
Enclosed
Global
Builtin
How to return multiple variables in function ?
Use comma seperator
What is returned by-default by function, when we return multiple values from function ?
Tuple is returned by default
Multiple Values packed in tuple by-default
How to return list from function ?
Enclose the return values in list then return
return [“This is a string”, “another one”,10]
What is unpacking ?
Returning multiple values , and collect them in multiple variables .Most important thing is no. of of return values & collecting variables should be in same
def create_something():
return [“This is a string”, “another one”,10]
a,b,c=create_something()
print(a,b,c)
What is the default return type of function ?
If no return statement is given, then function Returns
NoneType
What is EGB ?
EGB is an namespace
E - Enclosed
G- Global
B- Builtin