Re: some problems for an introductory python test

2021-08-10 Thread Terry Reedy
On 8/10/2021 5:27 PM, Hope Rouselle wrote: Terry Reedy writes: On 8/10/2021 9:15 AM, Hope Rouselle wrote: 2.__add__(3) SyntaxError: invalid syntax But then I tried: (2).__add__(3) 5 Add a space is easier. 2 .__add__(3) 5 Hah. That's brilliant! So cool. Python is a little loose

Re: on slices, negative indices, which are the equivalent procedures?

2021-08-10 Thread dn via Python-list
Apologies for lateness. Coincidentally, I've been asked to speak to our local Python Users' Group on slicing. Herewith an attempt to modify those demos around your data/question. Apologies if the result is thus somewhat lacking in flow. Also, whereas I prefer to illustrate 'how it works', I percei

Re: some problems for an introductory python test

2021-08-10 Thread Hope Rouselle
Terry Reedy writes: > On 8/10/2021 9:15 AM, Hope Rouselle wrote: > 2.__add__(3) >> SyntaxError: invalid syntax >> But then I tried: >> > (2).__add__(3) >> 5 > > Add a space is easier. 2 .__add__(3) > 5 Hah. That's brilliant! So cool. -- https://mail.python.org/mailman/listi

Re: some problems for an introductory python test

2021-08-10 Thread Hope Rouselle
Chris Angelico writes: > On Wed, Aug 11, 2021 at 4:14 AM Hope Rouselle wrote: >> >> Chris Angelico writes: >> >> > On Tue, Aug 10, 2021 at 7:25 AM Hope Rouselle >> > wrote: >> >> I came up with the following question. Using strings of length 5 >> >> (always), write a procedure histogram(s) th

Re: annotations cause dataclass fields type side effects

2021-08-10 Thread Barry
> On 9 Aug 2021, at 19:28, Lukas Lösche wrote: > > I'm on Python 3.9.6 and trying to make sense of the following behaviour: > from dataclasses import dataclass, fields @dataclass > ... class Foobar: > ... name: str > ... fields(Foobar)[0].type > type(fields(Foobar)[0].typ

Re: some problems for an introductory python test

2021-08-10 Thread Terry Reedy
On 8/10/2021 9:15 AM, Hope Rouselle wrote: 2.__add__(3) SyntaxError: invalid syntax But then I tried: (2).__add__(3) 5 Add a space is easier. >>> 2 .__add__(3) 5 >>> -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list

Re: some problems for an introductory python test

2021-08-10 Thread Chris Angelico
On Wed, Aug 11, 2021 at 4:18 AM Hope Rouselle wrote: > > Chris Angelico writes: > > [...] > > >> not disagreeing... and yeah I could have thought deeper about the > >> answer, but I still think "notthing has been OOP" -> "yes it has, they > >> just didn't realize it" was worth mentioning > > > >

Re: some problems for an introductory python test

2021-08-10 Thread Chris Angelico
On Wed, Aug 11, 2021 at 4:18 AM Hope Rouselle wrote: > > I totally agree with you but I didn't know that even numbers were like > that in Python. In fact, I still don't quite believe it... > > >>> 2.__add__(3) > SyntaxError: invalid syntax Yeah, that's because "2." looks like the beginning of a

Re: some problems for an introductory python test

2021-08-10 Thread Chris Angelico
On Wed, Aug 11, 2021 at 4:14 AM Hope Rouselle wrote: > > Chris Angelico writes: > > > On Tue, Aug 10, 2021 at 7:25 AM Hope Rouselle > > wrote: > >> I came up with the following question. Using strings of length 5 > >> (always), write a procedure histogram(s) that consumes a string and > >> pro

Re: some problems for an introductory python test

2021-08-10 Thread Hope Rouselle
Mats Wichmann writes: > On 8/9/21 3:07 PM, Hope Rouselle wrote: >> I'm looking for questions to put on a test for students who never had >> any experience with programming, but have learned to use Python's >> procedures, default arguments, if-else, strings, tuples, lists and >> dictionaries. (Th

Re: some problems for an introductory python test

2021-08-10 Thread Hope Rouselle
Chris Angelico writes: [...] >> not disagreeing... and yeah I could have thought deeper about the >> answer, but I still think "notthing has been OOP" -> "yes it has, they >> just didn't realize it" was worth mentioning > > Oh yes, absolutely agree. At the same time, inside the machine nothing

Re: some problems for an introductory python test

2021-08-10 Thread Hope Rouselle
Chris Angelico writes: > On Tue, Aug 10, 2021 at 7:25 AM Hope Rouselle wrote: >> I came up with the following question. Using strings of length 5 >> (always), write a procedure histogram(s) that consumes a string and >> produces a dictionary whose keys are each substrings (of the string) of >>

Re: on slices, negative indices, which are the equivalent procedures?

2021-08-10 Thread Hope Rouselle
Chris Angelico writes: > On Tue, Aug 10, 2021 at 7:24 AM Jack Brandom wrote: >> >> Greg Ewing writes: >> >> > On 6/08/21 12:00 pm, Jack Brandom wrote: >> >> It seems >> >> that I'd begin at position 3 (that's "k" which I save somewhere), then I >> >> subtract 1 from 3, getting 2 (that's "c", wh