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
| fruits = [('orange', 1), ('mangoes', 2), ('pineapple', 3), ('banana', 4)] | |
| total_fruits = 0 | |
| for fruit in fruits: | |
| total_fruits = total_fruits + fruit[1] | |
| print("total_fruits: ", total_fruits) |
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
| fruits = [('orange', 1), ('mangoes', 2), ('pineapple', 3), ('banana', 4)] | |
| total_fruits = sum([fruit[1] for fruit in fruits]) | |
| print("total_fruits: ", total_fruits) |
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
| cheques = [...] | |
| if cheques: | |
| for cheque in cheques: | |
| # run some action on cheque | |
| pass |
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
| cheques = [...] | |
| for cheque in cheques: | |
| # run some action on cheque | |
| pass |
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
| # this method was extract from a cheque class | |
| def create(self, vals): | |
| if "amount" not in vals: | |
| raise ValidationError(_("Cheque amount must be provided")) | |
| if "amount" in vals and vals["amount"] <= 0: | |
| raise ValidationError(_("Cheque amount must be greater than zero")) | |
| if "special_clearing" in vals and vals["special_clearing"]: | |
| vals["special_note"] = "Special Clearing" |
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 Book(object): | |
| def __init__(self, name=None, isbn=None, published_date=None, author=None): | |
| self.name = name | |
| self.isbn = isbn | |
| self.author = author | |
| # first instance of Book class | |
| refactoring_book = Book(name='Refactor', isbn='978-0201485677') |
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
| # defining a function with parameters | |
| function send_money(amount, currency_code, recipient_name): | |
| # code for sending money goes here | |
| return True | |
| # calling a function with arguments | |
| money_sent = send_money(2000, 'USD', 'Felix Otoo') |
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 ATM(object): | |
| @classmethod | |
| def _authenticate(cls, pin): | |
| # perform PIN verification and authentication | |
| return True | |
| @classmethod | |
| def withdraw_money(cls, pin, amount): | |
| if not cls._authenticate(pin): |
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
| @api.model | |
| def create(self, vals): | |
| if "amount" not in vals: | |
| raise ValidationError(_("Cheque amount must be provided")) | |
| if "amount" in vals and vals["amount"] <= 0: | |
| raise ValidationError(_("Cheque amount must be greater than zero")) | |
| if "special_clearing" in vals and vals["special_clearing"]: | |
| vals["special_note"] = "Special Clearing" |
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
| if "amount" not in vals and vals['amount'] > 0: | |
| raise ValidationError(_("Cheque amount must be provided and must be greater than zero")) |