This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #The first is used to initialise newly created object, and receives arguments used to do that: | |
| class Foo: | |
| def __init__(self, a, b, c): | |
| # ... | |
| x = Foo(1, 2, 3) # __init__ | |
| #The second implements function call operator. | |
| class Foo: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # The "timeit" module lets you measure the execution | |
| # time of small bits of Python code | |
| >>> import timeit | |
| >>> timeit.timeit('"-".join(str(n) for n in range(100))', | |
| number=10000) | |
| 0.3412662749997253 | |
| >>> timeit.timeit('"-".join([str(n) for n in range(100)])', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def decorator(func): | |
| @functools.wraps(func) | |
| def wrapper_decorator(*args, **kwargs): | |
| # Do something before | |
| value = func(**args, **kwargs) | |
| # Do something after | |
| return value | |
| return wrapper_decorator |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Why Python Is Great: | |
| # In-place value swapping | |
| # Let's say we want to swap | |
| # the values of a and b... | |
| a = 23 | |
| b = 42 | |
| # The "classic" way to do it | |
| # with a temporary variable: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # "is" vs "==" | |
| >>> a = [1, 2, 3] | |
| >>> b = a | |
| >>> a is b | |
| True | |
| >>> a == b | |
| True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| console.clear(); | |
| console.log("Welcome to the function jungle 🦌🌳🌲"); | |
| // calcular la temperatura actual del salon | |
| // ✅ Obtener un numero aleatorio entre 24-32 | |
| // - Obtener random entre el 0-8 y sumarle 24 | |
| // ✅ Imprimir "Temperatura: XXºC" donde XX es la temperatura anterior | |
| // ✅ Hacer una funcion que calcule la temperatura_interior y devuela el valor | |
| function obtener_temperatura_interior() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| puts "Enter your first name" | |
| first_name = gets.chomp | |
| puts "Enter your last name" | |
| last_name = gets.chomp | |
| full_name = "#{first_name} #{last_name}" | |
| puts "Your full name si #{full_name}" | |
| puts "Your full name si #{full_name.reverse}" | |
| full_name_len = full_name.gsub(" ", "").length | |
| puts "Your name has #{full_name_len} character in it" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| console.log("\t\tPair programming Lucia Fermin") | |
| var cities = { | |
| alicante: 96, | |
| valencia: 93, | |
| castellon: 91, | |
| murcia: 68, | |
| teruel: 70, | |
| granada: 88, | |
| gijon: 60, | |
| barcelona: 12, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #clean architecture layers | |
| # https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html | |
| # ^^you can read read here the beneficts of use this patterns to write better code | |
| # The dependency rule (->): dependencies can only point inwards | |
| # Infrastructure -> Application -> Domain | |
| # Summary: my business logic (domain) don't know infra or apliccation layers | |
| # Use case summary | |
| # Given a slug |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Cart: | |
| def __init__(self, user=None): | |
| self.user = user | |
| self.elements = {} | |
| self.discounts = {} | |
| # this is a factory | |
| @staticmethod | |
| def create(user): |