December 9, 2014

Week of 11/30/14 - Python Part 13: Wrapping Up

     Now, what Codeacademy is having me do is practice with using classes, by making me make a car class, and making a child class that inherits from that. However, I forgot that when you initialize a child class, instead of just letting it inherit all of the arguments of the old class, you have to rewrite all the arguments in the new initialization, instead of just the new ones. For example:
 
class Parent(object):
    def __init__(self, genes):      # Initializes class with arguments
        self.genes = genes

class Child(Parent):
    def __init__(self, genes, fun): # Initializes child class with inherited arguments
                                    # and new arguments. You need to do this if you
                                    # want to add more arguments to a child class.
                                    # Otherwise you wouldn't have to re-initialize.
        self.genes = genes
        self.fun = fun
     Next they taught me about file input and output, but I didn't really care all that much, mostly because I don't think I'd need to output to a file.
     That spells the end of the Codeacademy Python course. I went on trying to use Python's "IDLE" IDE (Integrated Development Environment), but I could not figure out how to use it, especially from the command line. I'll probably try to learn how to use it next week (seeing as I can't exactly use Codeacademy's output console and the code editor forever), and begin coding actual independent projects.
     A problem with how Codeacademy taught me how to code is that they taught me Python 2.0. I, however, have Python 3.0 installed, so a couple things have changed. For example, instead of the print statement, e.g. print "27", we have a print function, so the previous statement would be written as print("27"). This is one of the major ones.
     Another change is that in Python 2, 3 divided by 2 (3/2) is equal to 1 because this is integer division and integer division returned an integer. In Python 3, however, this changed to return a floating-point number instead (e.g. 3/2 = 1.5).
     One more change between Python 2 and 3 is that in Python 2, the function print range(3) would  print a list of numbers: [0, 1, 2]. However, if we use print(range(3)) in Python 3, it would print range(3). To print the list, we have to use print(list(range(3))).
     Finally, the input() function has been changed to save the input as a string instead of as an integer or float.

No comments: