Inheritance in Object Oriented Programming (OOP) means that you create a new class by extending an existing class. For example, suppose we have a class Shape with the attribute position. Then we can create a new class Circle by taking Shape and extending it by a new attribute center: Read the rest of this entry »
Archive for the ‘computer science’ Category
Posted by Ed on April 23, 2016
Posted by Ed on March 26, 2016
Have you ever wanted to try Linux? Here is how you can do it, and all you need is a USB memory stick. Read the rest of this entry »
Posted by Ed on February 7, 2016
Here are some nice github tutorials: Read the rest of this entry »
Posted by Ed on April 24, 2015
Check out this interesting article by Constantine Lignos called Anti-Patterns in Python Programming. It demonstrates with several examples how you should write code in Python.
Posted by Ed on April 23, 2015
Here is the best way to read a file line by line in Python 3.4: Read the rest of this entry »
Posted by Ed on April 22, 2015
In this blog post I will explain how generators are used in Python 3.4. Read the rest of this entry »
Posted by Ed on September 18, 2014
Here is a wonderful talk by Raymond Hettinger with the title Transforming Code into Beautiful, Idiomatic Python
His Twitter where he regularly posts short Python code.
Posted by Ed on August 29, 2013
Here is a great C programming tutorial by Adam. It’s currently made up of 87 videos where each video lasts for 5-10 minutes. I really like the drawings that illustrate what is going on in the memory.
I went through the tutorial by watching and simultaenously copying the source code. And before I would go to the next video I recreated the code from memory which I found best to learn the concepts.
Posted by Ed on April 2, 2013
Pythontutor is a website that lets you visualize your Python code.
For instance, type the following Python code into the window:
x = [1, 2, 3] # reference to the object that x points to y = x # create a copy of the list [1,2,3] and store its address at z z = x[:] # create a copy of the list [1,2,3] and store its address at z a = x.copy() # reference to the object that z points to a = z
Then, change from Python 2.7 to Python 3.3 in the drop down menu below the window and click the button Visualize Execution.
Click on forward to process the code and observe how the graphics changes on the right.
Pretty neat, isn’t it!
You can also change some settings such as choosing between Python 2.7 and Python 3.3 and using the address id instead of the arrows.
Change the following settings:
inline primitives and nested object -> render all objects on the heap
draw references using arrows -> use text labels for references
Then, paste the following code into the window:
myString = "hello" # observe how the id changes myString += " world" print(myString)
Observe how the id changes if you try to append the string
" world" to
That is because strings are immutable in Python such that Python first creates the new string object
The addess of this new object is then assigned to the reference