WTH is a Glyphicon?! Bootstrap, flask and still chugging away at this Python 2 course. Today I learned: Tuesday 14 June 2022

  • Continueing with Codecademy's 'Python 2' course:

    • I can confirm that functions in py are defined using the def keyword.

    • I just spotted another placeholder: %f

      • I'll figure out what this one means soon.
    • Instead of importing a whole library, which takes up unnecessary space. You can import just a single function instead. This is called functional import.

      • For example you can import just the sqrt function from the math library by doing this:

        • from math import sqrt

        • I also saw this from the flask tutorial:

          • from flask import Flask
    • Supposedly there is a 'Universal import' that allows you to import everything froma library.

      • But what is the difference between:

        • import math

        • &

        • from math import *

        • ?

      • Ah, I see now. If you use the latter option, you cannot define you own variable names if the name matches a function within the library.

        • For example

          • math.sqrt from the first option is different from sqrt in the second option.
        • So the tutorial suggests that you either stick to either 'import module' and type 'module.name'

        • or

        • Just 'import' specific variables and functions from various modules as needed.

    • You can use the 'print dir(module)' to print out all the functions within the module.

    • max(), min() and abs() are all built in methods that do not require importing a module.

      • abs() returns the absolute value, which means its distance from zero.
    • The type() function returns the type of the data passed into it.

      • Eg type(1.1)

      • Returns 'float'

    • You can add items to a list in python using the .append() method.

      • suitcase.append("lunch")

        • This will add a string with the text "lunch" to the end of the "suitcase" list.
    • For loops in python are different from for loops in Javascript.

      • My_list = [1,2,3,4,5]

      • for number in my_list:

      • #do stuff

        • The above code will perform an action for every number in that list.
    • Dictionaries are like lists, but their variables are accessed by key value pairs:

      • d = {'key1' : 1, 'key2' : 2, 'key3' : 3}

      • In the above, 'key1' points to the value 1, etc.

      • It looks like dictionaries are defined by using curly braces{}, and lists are defined using square braces [].

      • Dictionaries and lists haved different ways of removing items.

        • Dictionaries:

          • Del dict_name[key_name]
        • Lists:

          • list_name.remove("item_name")
    • The python 'range()' function is a shortcut to create a list.

      • The range function has three different versions:

        • range(stop)

        • range(start, stop)

        • range(start, stop, step)

      • In all cases, the range() function returns a list of number from start up to (but not including) stop.

        • Each item increases by step. So I guess if step is 3, then it will start with 1, 4, 7, etc.

        • If 'start' is omitted, it will default to 0.

        • If 'step' is omitted, it will default to 1.

    • Codecademy is very buggy. Sometimes I have the perfect code, and it still gives me an error. And when I request to see the solution, it presents either the exact same code, or an incomplete solution. Sometimes I need to reset the workspace and start again.

    • Started to learn about Bootstrap from this Toptal article from Tomislav Bacinger: https://www.toptal.com/front-end/what-is-bootstrap-a-short-tutorial-on-the-what-why-and-how