things which came out my laptop


I wanted to download few regional (marathi) videos from youtube. I found a interesting and nicely written python script called youtube-dl.
This script is written in object oriented way. This made may to dig out python more.

So I decided during this vacations I will be learning new (object oriented) scripting language, Python.

1) Swap in a statement
This question is very common in C, C++technical interviews, In Python, the simultaneous assignment statement offers an elegant alternative. Here is a simpler Python equivalent:
x, y = y, x
2) Indentations matters
Python programming blocks are grouped using indentations.


for i in range(x):
fact = fact * (x- i)
print fact


for i in range(x):
fact = fact * (x- i)
print fact

Above two snippet will generate two difference outputs, In second snippet print statement is part of for loop.

3) Range it!!
Python has inbuilt function, Range, which will generate list of numbers. There are other variations of range that can be used to produce different sequences:,

>>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> range(5,10)
[5, 6, 7, 8, 9]
>>> range(5, 10, 3)
[5, 8]

4) “Long Int” is really long:
Python has new datatype, long int. A long int is not a fixed size, but expands to accommodate whatever value it holds. The only limit is
the amount of memory the computer has available to it.