CHAPTER 4. CONTAINERS, BLOCKS, AND ITERATORS
PAGE 44
a = [ 1, 3, 5, 7, 9]
a[-1] -> 9
a[-2] -> 7
a[-99] -> nil
Software is about people, not code.
CHAPTER 4. CONTAINERS, BLOCKS, AND ITERATORS
PAGE 44
a = [ 1, 3, 5, 7, 9]
a[-1] -> 9
a[-2] -> 7
a[-99] -> nil
My name is Matt Blodgett, and I believe the most important problems in software development are non-technical.
I write from Chicago, Illinois.
Copyright © 2022 Matt Blodgett
3 comments :
Perhaps I am missing something - why does that make you sigh longingly. Is it the banality of the example?
No, that's not the case at all.
Coming from a C#/Java/C background, I'm trying to highlight features I've discovered in Ruby that make me long for it.
Ahh... that makes sense. I'm a bit like that with C and Python.
BTW, these examples give identical results in Python except for 'a[-99]' which raises an IndexError exception. I can see advantages to both approaches and both are better than a program crash!
Post a Comment