A Hundred Days of Code, Day 010 - Python Functions, Basics Done!

Today was hard! Notes ‘*args’ way to get multiple arguments without having to assign placeholders for them it scoops up all the arguments and gives it to the function in a tuple. I could then loop over it with for. I just put * in front of one of my placholders et voilà, def example_func(*catch_everything) I can define placeholders to catch specific arguments, but those need to be before my ‘*args’....

July 17, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 009 - Python Functions, Basics

Started up with learning about Python function basics, today. Notes follow. Using the Lerner pool of wisdom, as usual. Why do we need functions? DRY (Don’t Repeat Yourself), because we can take stuff that is repeatable, assign it a nickname and just call that nickname over and over, instead of tediously writing all that stuff over and over and over If want to modify something, I can just call it (by the nickname) and then add my little spice to it....

July 16, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 008 - Python Basics, Lists, Tuples, Dictionaries, Sets and Done!

This was an amazing run! Learnt lots. Done with the basics course. Woohoo! Notes With lists Not pythonic to mix types can iterate, slice and dice, search, get lengths, transmute them (for e.g. reverse items in them) just like strings can have lists of lists! lists are mutable, unlike strings. can change items/elements of a list If i create a list from another list, the new list items reference the old list items if i want to copy elements from a list rather than reference them, I’ll go newlist = oldlist[:] which will copy the elements from the old list into the new one, rather than create references to the old ones Realise that there is a difference between changing the values of a variable and between changing elements of a list....

July 15, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 007 - Python Basics, Variables, Basic Data Types, Strings and Loops

Started with the Reuven Lerner, Intro Python:Fundamentals course today. Made surprising headway, even though today was crazily demanding with work and personal stuff. Notes The difference between == and is If you want to see if two things are equal, use == like, is 2+2 == 4 If you want to know if two objects are the same thing. if they are just pointers to the same memory location, use is....

July 14, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 006 - Starting and Quitting Comprehensions

I know I said, I’d start with the basics, Reuven, but please forgive me this once :) Will do the rest, bottom up :) Have started up with this, because I’m fascinated with how folks manage to build in so much functionality into short, easy to read statements. To my mind, comprehensions are the pithy proverbs of the programming world. So here goes … Notes This style of writing code, comes from functional programming Functional Programming is another style of writing code It assumes that data is immutable....

July 13, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 005 - Magic Methods and Winding Up OOP

Done with Reuven Lerner’s OOP basics Notes len does the right thing across multiple types of objects. it counts characters in a string, elements in a list, and key-value pairs in a dictionary. how does it know how to do that? that is because len uses a magic method (methods that have a __ for a prefix and suffix) len uses the __len__ method which i can use in my own classes, to implement a len method for my classes If I choose to do so, I need to realise what those underlying methods expect to return and return the same type in my classes....

July 12, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 004 - Class Attributes and Inheritance

Learnt about Class Attributes and Inheritance, today. Notes The way we write functions/methods and define classes might look similar, class CrazyTalk(object): and def how_now_brown_cow(): The way they behave/execute, though is wildly different. Classes run / spring to life as soon as the program launches. Functions don’t, unless they are called. Realised that objects are containers. What you can do with the object depends on what is in it. Does it hold a dictionary with various methods to modify it?...

July 11, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 003 - Methods

Learnt about methods today. Notes follow … My understanding about methods? They are functions in classes that help me manipulate the data the objects contain when they are created. I have been using something them subconsciously all along. The __init__ method, that is called/run automatically every time an object is created. Aha A nice way to unpack the .notation i use Let’s say I have a class SquareNumbers that has a function (method) ­— x2 — that will, you know, square a number....

July 10, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 002 - Basic Exercises

Did a few exercises today. They were simple. Create a few classes, change them, modify them, use a list as an attribute and so on. In a couple of ways, this was just what I needed. One, I had an extremely busy day at work, and so I did not have the brain power to do anything complex, so I needed the bar really low any way. And two, I’ve realised, that I have always tried to just read a book and then leap mountains....

July 9, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 001 - Beginning With Classes

Notes I’ve taken from the videos I watched, today. This is my attempt at Feynman-ing (below), what I learnt so far. Classes and Object Oriented Programming started to come together for me, when I saw Kushal using them. To use my father’s carpentry analogy, I could in theory just hammer nails into wood to join them. But to make a really strong joint, I could use other methods. I could screw pieces of wood together, which is markedly better than just nailing them....

July 8, 2020 · Mario Jason Braganza