Although I’m very appreciative of it, I have not subscribed
to “The Economist” for years. Even I
can’t read that much each week. However,
I have been traveling some for work recently and when I do I treat myself to
the latest issue on the airport newsstand.
That’s where I most recently saw an article about the popularity of the
Python programming language. “Everybody”
seems to learning it.
Python is just one of hundreds of programming languages. It is popular now and in wide use. But it isn’t the only widely used language. But if everyone should learn to code, why not
Python?
“Coding” in general seems to be the mantra of educators and
Technological Evangelists everywhere these days. I’ve been puzzled by this for a long
time. (That’s an actual job title,
“Technological Evangelist,” I’m not making it up.)
Now, it’s valuable to have some idea what goes on under a
computer’s hood and a programming class can help with that. Also, programming may be the only formal
logic training most of us get these days: how to think through a decision tree
is Very Valuable.
But coding-for-everybody seems to emphasize the wrong
thing.
s = 'here, there, everywhere'
t = 'where'
i = 0
print (s[i:].find(t[i:]))
· Finally, most coding is maintenance of existing code. It isn’t the fun creation of new worlds, it’s the painstaking study of someone else’s existing code to figure out how to add a function or fix a bug. (When I used to manage programmers and ask one to tweak an existing program, the constant whine I got back was: can’t I just rewrite this from scratch?) I wonder if coding classes include maintenance in their curricula? I did a quick search and, while not finding a lot of hits, I did see a book: “Find the Bug: A Book of Incorrect Programs.” I have not seen the book and I know nothing other than the title, but I like the idea.
As alluded to above, the real value is business & systems
analysis and communications – oral and written communications. One can be trained in these, too, but that’s
harder and not as sexy.
Why the answer is 18:
s = 'here, there, everywhere'
t = 'where'
i = 0
print (s[i:].find(t[i:]))
· Individual characters can be enumerated in a string starting with zero for the first position. In the string called t above, with the value “where” the ‘w’ would be zero and the ‘r’ would be three.
· You can perform operations on portions of a string with an ‘index’ which is an expression inside square brackets. This means our string could be approached thus t[3] where the result would be ‘r’.
· If you add a colon to the index you are asking for everything in the string up-to or from the value. This means that t[3:] gives ‘re’ – that is, from the ‘r’ to the end of the string.
· For more fun, you can put a variable into the index. If we let i=0 and then we execute t[i] we will get ‘w’ because the value of i is zero and the zero position in t is ‘w’.
· If we combine that variable with the colon like t[i:] we get ‘where’ because we start from the zero position of t and go to the end of the string. That expression t[i:] appears in the code above inside the parentheses of the ‘find’ function.
· By the same process we can define the string s as ‘here, there, everywhere’ and i being zero, s[i:] is the same as s, ‘here, there, everywhere’.
· The find function consists of string.find() where the computer looks in the string for whatever is in the parentheses and returns the position of the first character. In the code above, (s[i:].find(t[i:])) then is this…
‘here, there, everywhere’.find(‘where’)
I apologize for that explanation’s length. It was challenging to write and probably more
challenging to read. When I first found
that example I thought it might be too easy but now I wish I had found
something more elementary still. Which
rather makes my point.
No comments:
Post a Comment