Would it be correct to say: [ ] aka square brackets, always surround the subscript of an array or list, i.e. here "n: is an integer, [n] always means the nth item, while ( ), round brackets or parentheses, separate and group items to control processing order, and identify subroutine calls, surrounding the argument list, if any?
On 9/26/18, Brian Duggan <bdugg...@gmail.com> wrote: > On Tuesday, September 25, Todd Chester wrote: >> Not to ask too obvious a question, but why does words use a [] >> instead of a () ? >> ... >> I am confused as to when to use [] and when to use () with a method. > > If a method is called without arguments, the () can be omitted. > > "a man a plan a canal -- panama".words() > "a man a plan a canal -- panama".words # <-- same thing > > [] acts on the return value -- it takes an element of a list > > "a man a plan a canal -- panama".words()[3] > "a man a plan a canal -- panama".words[3] # <-- same thing > > Brian >