Posts

Python: Functions - Part 1

Quick post Python functions:


Define a function and call it:

defadd(first_num, second_num): sum= first_num + second_num print(sum) >> add(1, 2) 3
Two types of arguments: positional and keyword:
Positional - defined by order of parameters in the method
Keyword - use the parameter name when calling the function

You can forget what order to use when all of your arguments are keyword arguments:
add(second_num =3, first_num =1)
But when mixing keyword arguments with positional you need to take care that all keyword arguments are at the end:

add(second_num =3, 3) SyntaxError: positional argument follows keyword argument
In the call below, the first argument of value "1" is taken in as parameter "first_num" based on it's position, so defining it again as keyword Python will give error:

>>> add(1, first_num =3) Traceback (most recent call last): File "<pyshell#9>", line 1, in<module> add(1, first_num =3) TypeError: add() g…

Onwards and Upwards

I have concluded that I a need a skill-upgrade. Although my day to day work requires C# and bit of Java, this is not going to be enough.

Javascript is no longer something that I can ignore, neither is Python. In fact JS has come a long way to be used to build a variety of applications - great UIs to services.

And Python, nothing more can be said about it. This language has become such that every programmer should know at least how to read Python code.

So this year, embarking on journey to learn Python and JS along with Angular/TypeScript - at least to the level of intermediate programmer.

Of course along with this delving deeper into core areas such as agile patterns and SOLID principles.

Python 101 - Part 1

PEP

Python Enhancements Proposal (guidelines) PEP 8: Style Guide For Python Code PEP 20: Zen of Python

Indentation

Used to mark blocks, curly braces no longer needed Recommendation is to use 4 spaces for indentation, be consistent and not to mix spaces with tabs

Modules

- Use modules available in Python
e.g.: import math
After importing use the module name to call functions:
math.sqrt(5) math.factorial(5)
from math import factorial -> factorial(5) # avoid using math from math import factorial as fac -> fac(5) #shorter name

Help (in REPL cmd)

- Get help on a module help(math)
- Get help on a function help(math.sqrt) help(math.factorial)

int, float

int(10), int(10.2), int(“10”)
float(10), float(10.2), float(“10.2”)

Nan,inf
float(“nan”) # not a number float(“inf”) # infinity

Passed CFA Level 2

Now on to CFA Level 2 - June 3rd 2017.

I really love this period of preparing for something worthwhile - which requires your full dedication, focus and attention. It's almost as if you become one with your goal.

Edit [26-July-2017]:
And I cleared it !

Passed CFA Level 1

Happy to share that I cleared CFA Level 1.
Level 1 is supposedly the easiest one out of all level, but it does require time and effort. Thanks to my loving family for bearing with me :)

Moving a window to another monitor

I had done this so many times using mouse and every time I did, I wondered why isn't there a key board short cut to do it. Dragging it felt so slow and at times it hindered productivity.
In Windows 7, the short cut key is:   
Win+Shift+left: to move the selected window to left
Win+Shift+right: to move the selected window to right
If you have only two monitors then pressing left or right again will switch the window between the left and right monitors.
I need to test this on more than two monitors. If you have 3 monitors, then let me know how it works.