nativo interview Flashcards
git: to make git ignore certain files
before you commit, create a .gitignore file and add them into it.
git: A good commit message
is written as a command. “Remove the cruft”
and the body is, what, why and how.
“Add user accounts to allow user logins by integrating django allauth”
Python: To stop a for loop, use the command
break
Python: To test if a number is even, type
number % 2 == 0
Python: To switch the keys and values of a dictionary to be the values and keys using a dict comprehension, type
{value: key for key, value in my_dict.items()}
Python: __init__ is a
method that runs right when a class is instantiated
Python: An alternative to putting all of the parameters and defaults in a class’s def __init__(self, my_attribute=1, my_attribute2=2): you can just type
class Myclass: def \_\_init\_\_(self, **args): self.my_attribute = args.get("Name", "Bill") self.my_attribute2 = args.get("Age", 20)
Python: Every method in a class must at least take the
self argument. def my_method(self):
Python: The (self) argument represents
the data from the instance you are calling the method on.
Python: Using self. in a class method allows you to
access the attributes of the instance you are calling the method on.
Python: This function will return def f(): return
f()
None
Python and Javascript imports start with
Python = from Javascript = import
PFJI
Python: To create a class that takes two arguments upon instantiation, and has a method, type
class Myclass: def \_\_init\_\_(self, arg_1="default1", arg_2="default2"): self.arg_1 = arg_1 self.arg_2 = arg_2 def my_method(self): return self.arg_one*2
Python: To return a random list item, type
import random
random.choice(my_list)
Python: To capture any parameters that are passed into a class when being instantiated, but were not defined inside the class beforehand, type
class Myclass: def \_\_init\_\_(self, **args) self.my_attribute = args.get("arg", "default") for key, value in args.items(): setattr(self, key, value)
JS: “use strict” is
a string you can add to the top of a file or function in order to
CS: The difference between an error and an exception is
An Error indicates a serious problem you should not try to catch. An Exception indicates a problem you might want to catch.
Python: A decorator is just
syntactic sugar for creating a closure
Python: The three ways to wrap a closure around a function and call it are
def add(a, b): return a + b
@closure_function_name def add(a, b): return a + b
add(1, 1)
or
add = closure_function_name(add)
add(1,1)
or
closure_function_name(add)(1, 1)
https: //www.youtube.com/watch?v=swU3c34d2NQ
https: //www.youtube.com/watch?v=MYAEv3JoenI
Python: Using a closure wrapper gives you an opportunity to
perform some operations before calling the original function (like logging) or altering the passed in parameters before passing them into original function or making the calling of the original function conditional