Once I got started with Python, I noticed a few things that I liked immediately. List, Dictionary, Set, and Generator comprehensions are things that I very much enjoy using. Although in a general sense it is basically just a way to iterate over these structures, their syntax is very enticing to me. Let's just use a brief example here.
new_list = [1, 2, 3, 4, 5] new_list = [num for num in new_list if num % 2 == 0] print(new_list) #=> [2, 4]
newArray = [1, 2, 3, 4, 5] newArray = newArray.filter(num => num%2 === 0) console.log(newArray) //=> [2, 4]
new_list = [1, 2, 3, 4, 5] new_list = [num*2 for num in new_list] print(new_list #=> [2, 4, 6, 8, 10]
This is just the surface of what comprehensions in Python can do but I am very much a fan of their syntax.
# Python def foo(): print('Hello World!') foo()
Even though these two functions are a bit different, the way that they are invoked is the same which makes it easier for me to grasp how to actually print out 'Hello World!'.
I am planning to be able to continue to practice Python using the Django web framework. I have started with Django but will need more time to be able to implement it the same way I could with a Rails application right now. I will also likely be writing about Python more as I continue to try to learn it so look out for a few more Python related posts here.