Posts

Showing posts from June, 2019

Lists vs. Tuples: Behind the Scenes

Image
Hi, welcome to this new tutorial! 😀 We will dive into the similarities and differences between lists and tuples. It’s very important that you understand their key differences, so let’s begin! 👍 🎓  Syntax and Structure The syntax used to define lists and tuples is very similar, but they differ in a very important aspect:  lists are enclosed in square brackets [ ] and tuples are enclosed in parentheses ( ). They  both contain values separated by commas  and those values can be of different types, so you can include integers, strings, floats, other lists, and even tuples as values. (Lists within lists are called “Nested Lists” and tuples within tuple are called “Nested tuples”). They have a  structure that is very similar to the grid that we used to work with strings . Each element can be accessed by using its corresponding index, like we did with strings in Weeks 1 and 2. The first value can be accessed using index 0, the second value using index 1, and so on… exactly lik

Recursion: Behind the Scenes

Image
Welcome to Recursion! Hi! Welcome to this introduction to recursion, it’s great to have you here. 😀 This is a very powerful concept in programming…  a function that calls itself!  I know what you must be thinking: What?! The function calls itself? Why would you want to do that? 😅 Recursion is used when the  result of a problem depends on the result of smaller versions of the same problem . Sounds strange? Don't worry! You will learn what it means with this tutorial. 😀 Let’s dive into the details  with an example, calculating factorial. Meet Factorial 👋 The factorial of a positive integer n is the result multiplying all the integers less than or equal to n. For example, the factorial of 3 is 3 * 2 * 1 (by convention, the factorial of 0 is 1) Factorial is denoted as  n!  in mathematics. This is the code we will be working with. Please take a moment to analyze it. Base Case I’m sure that you noticed that there is a call to factorial within the definition of

Short-Circuit Evaluation in Python: Behind the Scenes

Welcome to this short tutorial on Short-Circuit Evaluation, an important aspect of Python Boolean operators that will be key for your future in Computer Science. Let’s begin!  👍 🎓  A Quick Recap In the tutorial:  Boolean Expressions and Operators , you learned about truth tables. Here is a quick recap: With the  and  operator, an expression evaluates to  True  only if both operands are  True  (in this case, the operands are expressions that evaluate to a Boolean value). If either one of them evaluates to  False , the entire expression evaluates to  False . For example: >>> 5 > 6 False >>> 7 < 9 True >>> 5 > 6 and 7 < 9 # Equivalent to -> False and True False >>> 5 < 6 True >>> 7 < 9 True >>> 5 < 6 and 7 < 9 # Equivalent to -> True and True True With the  or  operator, an expression evaluates to  True  if either one of the operands evaluates to  True . If they both evaluate to  Fa