Posts

for loop and slice

for statement iterates on any discrete sequence of items – as in Java. The syntax is simple: f or <variable > in <sequence> :     <statement> Eg.: words = [ ' this ' , ' that ' , ' another ' ] for w in words:      print (w, len(w)) Side-note here –       for w in words[:]: print (w)    has the same effect as      print (words) You can update a list within the for loop – unlike Java. for w in words:      if len(w) > 6 :           words. remove (w) But, better use a slice to end up with the expected effect in some cases. For instance, the following is an infinite for-loop: for w in words:      if len(w) > 6 :           print (w, ' here is one' )           words.insert( 0 , w)      else : print (w, ' nope' ) This is because, it keeps iterating on the current list – the list that keeps

The good/old control statements – if

if statement has 3 keywords only and a straightforward syntax: if <cond-1>:      <stat-1> elif <cond-2>:      <stat-2> else:      <stat-n> Conditions seem to be ending with ':'. 'else' is a condition also here – "otherwise". like default of switch . Letting the following equally work: if x < 0: x = 0; print('Negative changed to zero') elif x == 0: print('Zero') elif x == 1: print('Single') else: print('More') as well as if x < 0:      x = 0      print('Negative changed to zero') elif x == 0:      print('Zero') elif x == 1:      print('Single') else:      print('More') Note ';' as line separators between same-level/inner statements. So – `;` and line-separator seem to be  equivalent at such use (?) Mental note - see whether this is accurate, and can generalize this to their other/all use. The following is an error thou. Looks like me

Indentation!

Discovered indentation/errors of Python. Knew it – but, not having used it, hadn't encountered it. I'm sure there's a way to simply handling them. But frustrating still. Kind of makes you loose respect to the language. what it does depends on where/which column you type. not what you type. 

Python - what for?

I liked what this blog said re. the motivation ("1. Figure out what motivates you" section about 1/5th of the page): Data science / Machine learning Mobile apps Websites Games Hardware / Sensors / Robots Scripts to automate your work Mine is – Data science / Machine learning , and that's about it. And Scripts to automate your work , but that comes as a by-product. I've got other technologies in tact for those others. Python is algorithms to me. Not sure how comprehensive the above list is (neither does the author himself - says ".., such as"), but suits me – serves the purpose. Lays out a view.  

..And the very first step

Image
The very first step is to install the thing into my work environment. My work environment is Eclipse/Oxygen. Doesn’t take long – PyDev it is. The installation link is http://pydev.org/updates . Downloaded PyDev and its source – NOT Mylyn: PyDev perspective appeared&opened fine. Seems all OK w/the installation. Downloaded Python interpreter from here – had overlooked this before.  Gave me error when i tried to configure the console: Python location on my disk is C:\Users\<myUserNameHere>\AppData\Local\Programs\Python\Python37-32. I would have expected it in Program Files folder but voila. Things are/might be a little differet w/dynamically typed languages. I'm statically-type language kind. This a good reminder to device that mental switch to those. To switch, at choice, to dynamically-typed coding mode. "Python console" now opened on Eclipse. Saw this right off when I opened Python console :) All, i mean all seems OK now. 

Intro

I’ve come across with Python 3-4 years ago while i was looking up memoization. It just popped up on the list&i clicked. I was impressed w/what i saw. Python was just another scripting language to me till then. I saw its rich library of built-in algorithms when i dug in. And Python is of big use, if not (semi-)mandatory in the career line I’d like to expand on. Not to mention my professional interest. So here we do. The first step is to find resources (online) of convenient use to me.