[TUHS] python

Dan Cross crossd at gmail.com
Sat Aug 5 07:30:21 AEST 2023

On Fri, Aug 4, 2023 at 5:17 PM Douglas McIlroy
<douglas.mcilroy at dartmouth.edu> wrote:
> > Most of the time I'd rather not have to care whether the thing
> > I'm printing is a string, or a pointer, or an integer, or whatever:
> > I just want to see its value.
> > Go has %v for exactly this.  It's very nice for debugging.
> Why so verbose? In Basic, PRINT required no formatting directives at all.

There is a form in Go that doesn't require the "%v"s.

: chandra; cat v.go
package main

import "fmt"

func main() {
        fmt.Println("Hi", "there", "world", "pi is close to", 3.14159)
: chandra; go run v.go
Hi there world pi is close to 3.14159
: chandra;

I believe that `%v` exists so that one can compose it with other
formatting directives of various kinds; perhaps one wants to print the
string representation of an object with no additional ceremony, but
wants to emit a number in some specific format.

        - Dan C.

More information about the TUHS mailing list