python basics
module
it is just a python file which may hold functions, classes, methods, variables. for import we can use import
as show below.
import sys #to import full module
from datetime import date #to import submodule
from time import time #to import specific function, it can then be called directly
Note: functions are not bound to any class whereas methods are bound to class
global variable
print(__name__) #output: __main__
#if we have another module (different python file) to print __name__ variable
#import the other module in main python file
#then the other module will print __module__ and main will print __main__
one way to use it:
if __name__ == "__main__":
print("invoked when directly called")
else:
print("invoked when imported as module in other file")
dymanic typed
It is dynamically typed language, means data types are inferred.
var = 1
print(var)
lambda functions
inline function, example for square we can use like below
x = lambda a : a * a
print(x(2))
Comments