[Tutor] How to manipulate a user's input twice in one statement

Goran Ikac goranikac65 at gmail.com
Wed May 17 10:24:47 EDT 2023


Here we go: the concept!
But first: thank you, people, I've already learned a lot from your answers
and comments. Now I know, among other things (inline operator existence,
for example) that the problem cannot be solved the way I wanted, and - even
if it could - it wouldn't be a good, pythonic way. Mr. Gauld, I'm not
competent to question the work of the genius - the language itself. I'm
far, far from that (as obvious).
Now, the concept:
Mr. Gauld: "A method is a technical term that means an operation of an
object defined in a class. It is more or less the same as a function ..."
I thought so, but I did not take "... except that it's part of a class"
into account. That's how I started all this mess:

>>> removesuffix(some_string, some_string[1:])
Traceback (most . . . )
NameError: name 'removesuffix' is not defined
>>> help(removesuffix)
Traceback (most . . . )
NameError: name 'removesuffix' is not defined
>>> help(str.removesuffix)
Help on method_descriptor:
removesuffix(self, suffix, /)
    Return a str . . .

Aha! So, "removesuffix" can be used as a method applied to an object (the
instance of <class 'str'>), but not as a function with a string as the
first argument. The first argument must be "self". OK.
Then I tried:

>>> input().removesuffix(input()[1:])

... and it didn't work as I expected. That's where I decided to ask for
help. But

>>> result = 3 * (2 + int(input('Please, type a number: '))        # one
"input"

... worked, and I guessed if I can make the method work like a function or
an operator would.
Obviously, I need to learn better about classes and methods.

Thank you, people, very much for your time and effort!
Love from Croatia
Goran


More information about the Tutor mailing list