I have recently started learning Python programming and will be sharing my experiences (the highs & lows included!) with it. I am a R user and find it to be a wonderful open source programming package. Right now eager to see what Python has in store for me.
I found an interesting feature in Python. It starts counting from ZERO!
Okay, so far I have used R. For accessing say, the first element from a vector in R, I did something like this,
x <- c(‘R’, ‘is’, ‘open source’)
The output that I get is,
Say, I want the third element of the same vector, then,
And the output is,
 ”open source”
Well this was fine with me because, I learnt counting from 1!
But, Python has different rules for counting. As mentioned earlier, the counting begins at Zero. If I write a similar code in Python,
x = [‘R’, ‘is’, ‘open source’]
This is what I get,
Right, I get the second element of the list. So if I want the first element, I should pass this command to Python,
To which the output is
which is the last element of the list.
Also, noticed that Python won’t print a stuff unless the stuff is an argument of the print() command.
There is a module/ library called as os in Python.
I imported this library in Python and used it along with the command listdir to get a list of all files in a specific directory in my device!
a = [file for file in os.listdir(path)]
Here, path is the path of the specific folder. Python displays the names of files included in it when the above code is executed. If I want only files ending with specific extensions, (say, .pdf), then the following helps!
a = [file for file in os.listdir(path) if file.endswith(‘.pdf’)]
That’s it for the day!