Indexing in lists

8 views
Skip to first unread message

David Wishart

unread,
Jun 4, 2026, 1:00:23 PMJun 4
to Numbas Users
I've come across something strange if I try and sum a list. In short the indexing appears inconsistent, best explained by the example I've made.


Is taking subsections of lists to be avoided?

Martin Jones

unread,
Jun 5, 2026, 4:19:49 AMJun 5
to Numbas Users
Hi David
The issue seems not to be with the sum function, but with indexing the list like that.
In your example you will find that array[0..2] = [5, 10] which perhaps unexpected.
Martin

Christian Lawson-Perfect

unread,
Jun 11, 2026, 9:22:44 AM (14 days ago) Jun 11
to numbas...@googlegroups.com
I think you're just used to a different convention. Numbas uses the same convention for slices as python: [a..b] takes the elements from index a, up to but not including index b.

--
You received this message because you are subscribed to the Google Groups "Numbas Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numbas-users...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/numbas-users/70806863-052a-45b0-8bf4-ad011685ad6an%40googlegroups.com.

David Wishart

unread,
Jun 15, 2026, 5:05:08 AM (10 days ago) Jun 15
to Numbas Users
Thanks, that makes sense. Python isn't really something I've done a lot of. 
Reply all
Reply to author
Forward
0 new messages