To catch anyone up reading this, I started the Back End, SQL, and DevOps with Python course that is offered by Nucamp late last year and as of the writing of this post, on the last course and will have an early March graduation.

I have been trying to learn Python for what feels like an eternity now but now with this blog, aside from showing what steps I've taken in this journey, I also want to use it as a tool to test my understanding and explain some concepts I have come across in my own words.

I finished this course back in late December and only have somewhat touched Python as a whole in the course that came after it. The following are some explanations for the things I learned during the Python Fundamentals course.

Conditional Statements

One of the great things of the Python language is that everything more or less reads easily. Your normal math conditions are supported (equals, less than, more than, etc) and are regularly used. One such example where they are used are for if statements.

For example:

a = 10
b = 5
if a > b:
  print("a is greater than b")

One thing to point out from the example is the importance of the indentation. Python relies on whitespace to determine the scope of the code that is going to be executed.

Another example where your typical math conditions are used are for elif statements. This statement is another way of saying 'if the previous conditions aren't true, complete this'.

a = 33  
b = 33  
if b > a:  
  print("b is greater than a")  
elif a == b:  
  print("a and b are equal")

In the event that nothing comes up as true, we are able to use an else statement that will catch anything that isn't caught by the previous conditions.

a = 200  
b = 33  
if b > a:  
  print("b is greater than a")  
elif a == b:  
  print("a and b are equal")  
else:  
  print("a is greater than b")

While Loops

Some thing that I ran into a lot while attending this class were while loops. These are used to execute a set of commands as long as whatever condition provided is true.

For example:

x = 1
while x < 10:
  print (x)
  x += 1

This set of code while the value of x is less than 10, will print the value of x and add 1 to it's value. It is important to add/subtract to the variable being provided or utilize break/continue/else statements (which will be covered shortly). The reason we want to add some sort of condition is due to the loop never ending which will cause a system to hang.

Break statement

A break statement can be used to stop a loop even while a given condition is true.

Using some of the code from the previous example:

x = 1
while x < 10:
  print(x)
  if x == 5:
  break
i += 1

The moment the value of x became 5, the loop ended and the value of x did not continue to increase like it did in the first example.

Continue statement

A continue statement is a way to stop the iteration that is running then continue with the rest of the iteration.

x = 0  
while x < 6:  
  x += 1  
  if x == 3:  
    continue  
  print(x)

These are just some of the things I covered on week 1! I had some trouble understanding at the time but towards the end of the course, everything started to come together. Having a great instructor also helped. The rest of the course builds on top of these concepts and I was able to take these lessons and build a basic expense tracker. More posts for the things I learned during this bootcamp are on the way so stay tuned and thanks for reading!

Takeaways from the Python Fundamentals Course @ Nucamp