# Rewrite printf with print

**URL:** https://discourse.julialang.org/t/rewrite-printf-with-print/122193
**Category:** General Usage
**Created:** [November 3, 2024, 7:10am UTC](https://discourse.julialang.org/t/rewrite-printf-with-print/122193 "2024-11-03T07:10:29Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![hack3rcon](https://avatars.discourse-cdn.com/v4/letter/h/96bed5/32.png) [@hack3rcon](https://discourse.julialang.org/u/hack3rcon)
#### Post date: [November 3, 2024, 7:10am UTC](https://discourse.julialang.org/t/rewrite-printf-with-print/122193/1 "2024-11-03T07:10:29Z")

</div>

Hello,

```julia
using Printf
function twoTimesTable()
    for h = 1 : 12
        @printf("%2d x 2 = %2d\n", h, h*2)
    end
end # twoTimesTable
twoTimesTable()

```

How can I make this `printf` with `print`?

Thank you.

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [November 3, 2024, 8:45am UTC](https://discourse.julialang.org/t/rewrite-printf-with-print/122193/2 "2024-11-03T08:45:06Z")

</div>

In this simple case you can manage the spacing manually

```julia
       function twoTimesTable2()
         for h = 1:12
           strh = string(h)
           out = h*2
           strout = string(h*2)
           print(' '^(2-length(strh)), strh, " x 2 = ",
                 ' '^(2-length(strout)), strout, "\n")
         end
       end

```

but are you sure want to reimplement `Printf` features in general? That’s a lot of work that was already done for you. `twoTimesTable2` is also noticeably slower and allocates more ((160 allocations: 4.523 KiB) \> (48 allocations: 1.406 KiB)), and it’ll also be a lot of work to optimize things up to par.
