• Decorators in Python

    By George El.March 2019Reading time: 2 minutes

    In this post I will explain decorators in python. This is a rather advanced topic. You should first read about First class functions and Closures, in previous post. As we saw in previous post, functions can accept functions as arguments and return functions. Lets see an example. def outerf(fn): from datetime import datetime def innerf(*args, **kwargs): print (datetime.

    Read More...
  • First Class Functions in Python and Closures

    By George El.March 2019Reading time: 2 minutes

    In this post I will explain first class functions. According to wikipedia: “In computer science, a programming language is said to have first-class functions if it treats functions as first-class citizens. This means the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data structures.

    Read More...
  • Generators and Generator Expressions

    By George El.March 2019Reading time: 3 minutes

    In this post I will explain generators and generator expressions. Please read first the post on iterables and iterators. Generators are iterator objects that we can call to get the values one at a time. When a function has a yield statement, it returns a generator object. Then we can iterate through this, using a for loop or the next method.

    Read More...
  • Iterables and Iterators

    By George El.March 2019Reading time: 4 minutes

    In this post I will explain the what is an iterable and what is the difference between Iterators and Iterables. An iterable is every object that can be iterated. In order for this to happen it must implement the __iter__ method, and the __iter__ method must return an iterator object. An iterator object is an object that implements the __next__ method.

    Read More...
  • True and False in Python

    By George El.March 2019Reading time: 2 minutes

    In this Post I will describe what is True and False in Python. Then how to use “all” and “any” to combine these values and finally make a function that will check if an ip address is valid. In python all numbers are True except 0, every object that is not None, every string that is not empty, every list that is not empty, every dictionary that is not empty.

    Read More...
  • Local, Enclosing, Global, and Builtin Scope in Python

    By George El.March 2019Reading time: 2 minutes

    In this post I will explain the difference between the various scopes in python. By scope we mean that each variable, depending on where it is defined, has a certain area where it is valid and as a concequence has also a certain lifetime. Lets start with an example a=1 def func(): a=2 print(a) func() print(a) We have two variables called “a”, one is defined outside of anything and we say it has a module or global scope and the other one is defined inside a function and it has a local scope.

    Read More...
  • Classes in Python

    By George El.March 2019Reading time: 6 minutes

    In this post I will explain what classes are and then I will show you how to create instance methods and class methods and what is the difference between them. Then I will also show you how to create static methods. What are classes? Classes are blueprints that represent real life objects.

    Read More...
  • Lambda Expressions in Python

    By George El.March 2019Reading time: 3 minutes

    In this post I will explain lambda expressions in python. Simply put, lambda expressions is another way to create a function in python. However this function has some restrictions. It does not have a name (that’s why they are also called anonymous), they can not have assignments they do not have a ‘return’ keyword and they can only be one line.

    Read More...
  • How to Use the Kwargs in Python

    By George El.March 2019Reading time: 3 minutes

    In the previous post we saw how to unpack an iterable using the * operator and how to pass parameters to functions using the * operator. In this post I will show you how to pass parameters to functions using the ** operator and how to combine * and ** together.

    Read More...
  • Unpacking in Python and the * operator

    By George El.March 2019Reading time: 3 minutes

    In this post I will explain what is unpacking and how it is used in Python. I will also explain how the “*” operator is used in unpacking. In another post I will explain the ** operator. Unpacking means that we assign an iterable to more primitive data types. For instance, lets say I have a list l1 = [1,2,3] and I want to assign a to 1, b to 2, c to 3.

    Read More...