I’m Learning Python part 10 (last one)

I'm Learning Python part 10

(last one)

Python Logo

Back to blogging

As usual, I will apologize for not blogging for a long time.
I have been very busy, university exams, university projects, job projects, teaching and learning.

Python Course

At Damascus University, in the faculty of informatics we managed to create free courses to students, and I was one of the teachers there, I taught Python to students.
As far as I know this course was the first Python course in Damascus University.
Even though the students were a few (actually a very little few about 8 ~ 10 students) the course was great. We managed to learn Python 2.6 Syntax, a little bit of its standard library and a little bit of PyQt4 in about 7 days x 2 hours daily.
As far as I know too, students understood it and found it great, and I hope they’ll be using this great language more in their programs.

Why last one?

The tour with Python ends here, while it ends here it starts here too, it ends here because so far you’ve learned what you need to start your own path in Python. And it starts here because you’re fully equipped with the base tool to discover more tools, I’ll let you discover the standard library and 3rd-party libraries on your own, because everyone differs in his/her interests.
I’ll be blogging more on more technical issues but they might not be I’m Learning Python series :).
Let’s stop talking here and move directly to the heart of our last lesson.


The last part introduced classes, how to define them, how to use them. This lesson will continue to explain classes and functions more.
Defining a function:

Defining a class:

The constructor of the class is defined using the special name __init__:

The method inside a class is just a function which receives the object instance as its first parameter:

Properties are fields encapsulated within a function to get their values and might be encapsulated withing a function to set their values. These two functions allow you to do your business logic over the values before allowing the user to read/write them.

Defining an object instance of the class is done by calling the class constructor:

If the constructor takes a list of parameters you might specify them when calling it:

Properties after defining an object instance can be used as if they were fields:

More and more about functions

Functions can be used in many ways.

Functions with default values

You can let the parameters of the functions have default values, so that if the user didn’t supply them they’ll have valid values:

What if I want to supply the second paramter without supplying the first one and the third one? The solution is by:

Passing specified parameters

You can choose the paramters you want to supply and with any order you want:

You can see that this way is useful, you can choose which parameters to pass and in what order :).

Passing unlimited count of paramters

Yes you can do it, you can call a function and pass it any count of parameters you want:

So args actually is enumerable type, may be a list ;).

Passing unlimited named parameters

Hmmmm, yes you can too specify names for those unlimited parameters of yours:

So kargs actually is a dictionary.
If you don’t already know, dictionary.iteritems is a method that iterates over the keys and values of the dictionary, yielding a tuple every iteration, the first item of the tuple is the key, and the other is the value.
dictionary.iteritems is a great method for iterating over a dictionary of unknown keys.

Overloading and why I don’t need it here

Overloading is simply more than one instance of the same function with one or more of the following points achieved in them:
* The count of parameters differs between them.
* The types of the parameters differ between them.
* The prder of the parameters differ between them.

Using what we’ve learned so far, we can say that the first point can be achieved using one function, by using default values for the parameters.
The second point can also be achieved using one function since Python has no strict data types to variables and parameters.
The third point can also be achieved using one function, by using paramters names while calling you can change the order of parameters passed.
And so I can continue coding without overloading.

Last Words

After learning how to implement classes and functions properly you can start your path on learning Python standard library and 3rd-party libraries. Python is widely supported and you won’t find difficulties in using it as your main programming language.
In the last two months I learned how to use Python to develop web applications using Django (pronounced yangoo), and being an expert ASP .NET developer I assure you, Django is easier and more fun to code than ASP .NET. I made a testing website from the book I read – The book was: Django 1.0 Website Development, by my colleague and friend Ayman Hourieh -, the website is for sharing bookmarks, it is now hosted for free at AlwaysData here http://mpcabd.alwaysdata.net
You can do in Python whatever you want with less coding. Enjoy your life more.

The End

It is the end of this course but the start of your path.
I hope you enjoyed it, and that I could give you the information in a nice and easy way.
For any questions or suggestions you can leave your comments here.
Thanks for being patient :).
— Abd Allah Diab

3 thoughts on “I’m Learning Python part 10 (last one)

  1. We’re trying to get an Arabic page started on the Python Wiki:


    Is there anything in the way of Python code snippets and explanations in Arabic that you or your students would be willing to provide?

    Thanks for taking this request into consideration and for posting some of the course notes.

    Carl T.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.