1

in Julia, im trying to check the type of a variable and i expected it to show both the type and the value like 'int 10'. but when i use typeof(x), it just shows the type, e.g., Int64. how can i display both the type and the value of a variable in the terminal?

1
  • If you put your variable in a vector the repl will show the value(s) and the type, e.g. [x] or display([x]) (when calling from a shell). Commented Jun 15 at 19:30

1 Answer 1

1

You can do:

x = 10
println("$(typeof(x)) $x")

or just:

@show x

which prints:

x = 10

(showing both the name, value, and from the REPL you'll still see the type if you want with typeof(x))

If you want type + value in one string:

println("$(typeof(x)) $(x)")

Example output:

Int64 10
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.