Posts

Showing posts from November, 2017

Returning several values from a single function call: BEHIND THE SCENES!

Image
Hi! Welcome to this new session where we will learn HOW TO RETURN SEVERAL VALUES FROM A FUNCTION! Let’s get started! What we’ve learned so far is that we can return a value from a function to the scope that called the function and then save it to a variable for later use. But… what if we want to return more than one value? This is where our newly discovered friends come into play , TUPLES AND LISTS! If we return a tuple or a list from a function, we can return several values and assign them individually to their corresponding variables (We will see this in detail in the next diagrams).  We’ve learned that we can display the values returned by a function using print(). Since lists and tuples are iterables, we can iterate over their elements using a for/in loop like the examples below. We can also access each individual element by its corresponding index. But… wait a minute! What if we want to store the values returned by the function

Indexing tuples and lists that contain tuples and lists: BEHIND THE SCENES!

Image
Indexing Tuples and Lists that contain Tuples and Lists Hi! Welcome to this  “Indexing tuples and lists”  tutorial. We will be covering the principles behind  indexing tuples and lists that contain tuples and lists as elements  (they can also contain other data types, we’ll see an example of this right away). Presenting the examples we will be working with! As promised! Here are the two examples we will be working with during this tutorial. As you can see, we have a list and a tuple but the curious thing about them is that some of their element are also lists and tuples. NOTE:  In these examples lists contain lists and tuples contain tuples, but lists can contain tuples as well and viceversa Finding an element in this data structure Let’s analyze the question presented in the slide above by following the diagram below. “How can we find  "house3"  in  List1 ? We’ll start by  breaking down the structure of the outermost list . If we look ca

Object Oriented Programming: Classes and instances BEHIND THE SCENES!

Image
Object Oriented Programming: Classes and Instances Hi! Welcome to this section! First of all,  congratulations!  You’re already halfway through the course. You should be very proud of yourself :-) In this section we are going to start talking a little bit about classes, what they are and how they can represent real objects. You will even learn that YOU are an example of Object Oriented Programming (OOP) and you didn’t even know it! So… Let’s get started! Classes are like blueprints, we use them to represent an abstract notion or idea of how we describe real world objects according to certain criteria. For example, House is the notion we have of a structure where people live that has bedrooms, bathrooms, floors, roofs, ceilings, and so on… they share some characteristics, but they don’t necessarily have to be exactly the same for us to consider them houses. This is what we would represent as a CLASS, the abstract notion of a house. Now, if we refer to a specific

Object Oriented Programming: Methods BEHIND THE SCENES!

Image
Object Oriented Programming: Methods Hi! Welcome to this second part of the Object Oriented Programming Tutorial. In this section we are going to study very powerful concepts in Object Oriented Programming.  METHODS! Let’s get started! Remember the example we worked with in the first part of the tutorial? If not, don’t worry, here we have the code to refresh your memory. We covered naming the class, the  __init__( )  function and what instances are and how to create them. Now we will discuss what  METHODS  are. The functions below  __init__( )  must be familiar to you, they are exactly like function we have been working with, BUT notice that now, these functions are inside what we call a class. This changes the scenario a little bit, but you must remember that they are still functions that can be called with an input, if necessary. Let’s dive into METHODS! When you create an instance, that instance will have access to all the methods