CSC148 has been a fun (albeit sometimes confusing) course so far in the first three weeks. I remember when I first learned about creating classes in CSC108 and feeling how all of a sudden, so many more possibilities have opened up to me; the way we are able to define literally any attribute in a class and create methods for specific classes really excited me and I started thinking of ways on how I could use classes.
Well, I sort of relived that feeling again when I learned about super classes in CSC148, and again, my mind kind of started imagining all the stuff I could do with having classes inherit attributes from other classes. One of the cool aspects using super classes is that a lot of parallels can be drawn in real life in terms of classification; for example in class, our prof used a Person super class and an Employee class that inherited methods and attributes from the super class. In real life, Person is a more general classification than an Employee, and thus it makes perfect sense to me why Person would be the super class. On my spare time, I made a Quadrilateral class to test my understanding of super classes. It started off as a Rectangle super class and a Square class that inherited the Rectangle class' area and perimeter methods. Then I decided to make a Quadrilateral super class on top of the Rectangle class, which made defining the area a bit trickier (with all the angles and such....it was also the first time I realized Python's math.sin() took the integer as a rad, so I had to make adjustments).
In lecture, we also learned list comprehension. It saves a lot of time and space, for example, instead of writing around 3 lines of code for a for loop that is to append every item in a list to a new list, we can condense that all into one line in the format of something like this:
L = [x for x in A]
where L is the new list you are trying to make, and A is the list where you are getting your items from. Learning shortcuts, or shorter ways of writing code is also valuable knowledge, especially when functions get longer and longer to write.
All in all, it was a very interesting and educational experience, and I'm looking forward to learning more!
No comments:
Post a Comment