Hi Joannah, and welcome!

On Thu, Jun 01, 2017 at 05:17:49PM +0300, joannah nanjekye wrote:

[...]
> My proposal is we provide a way of functions returning multiple values.
> This has been implemented in languages like Go and I have found many cases
> where I needed and used such a functionality. I wish for this convenience
> in python so that I don't  have to suffer going around a tuple.

Can you explain how Go's multiple return values differ from Python's? 
Looking at the example here:

https://golang.org/doc/effective_go.html

it looks like there's very little difference. In Go, you have to declare 
the return type(s) of the function, which Python doesn't require, but 
the caller treats the function the same.

The Go example is:

func nextInt(b []byte, i int) (int, int) {
    for ; i < len(b) && !isDigit(b[i]); i++ {
    }
    x := 0
    for ; i < len(b) && isDigit(b[i]); i++ {
        x = x*10 + int(b[i]) - '0'
    }
    return x, i
}


which the caller uses like this:

x, i = nextInt(b, i)



In Python, we would write exactly the same thing: inside the nextInt 
function, we'd return multiple values:

    return x, i

and the caller would accept them like this:

    x, i = nextInt(b, i)


So the syntax is even the same. How is Go different from Python?


-- 
Steve
_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to