A module usually corresponds to one .py
file containing Python code, A Python module which can contain submodules or recursively, subpackages is called a package
. Technically, a package is a Python module with an __path__
attribute
The default implementation of python is CPython
(interpreter is writting in C language)
myString = "abcdedg"
#begins at the end -> ends at 0th index -> decrements index every step
print(myString[::-1]) #begin:end:step
The main difference between lists and tuples is that lists are mutable whereas tuples are immutable
Pure functions are functions that meet the below conditions
- They should not produce any side effects
- For the same input they should produce the same output
- They should not modify data outside their scope
A model
in django is a blueprint to a database table where its fields are mapped to the corresponding columns in a table.
A higher order function is function which does atleast one of the below two things. It is generally used to empower a function
- It accepts a function as its parameter
- it return a function as its return value
Decoraters are syntactic sugar for higher order functions in python, they enhance the underlying function with a resuable feature
def pretty_print(func):
def wrapper(*args, **kwargs):
print("#### PRETTY ####")
func(*args, **kwargs)
print("---------------")
return wrapper
@pretty_print
def say_hello():
print("Hello!")
say_hello()
Dunder is a short form for Double Under (Underscore) , these methods are not to be invoked directly but they are automatically invoked whenever a certain action is performed on a class. One of the most used methods is __str__
class Animal:
def __str__(self) -> str:
return "string representation"
pass
animal1 = Animal()
print(animal1)
__str__
is invoked whenever we try to print the class object and also when we explicitely demand a string representation (str(animal1)
)