println
.. println(x)
Print (using :func:`print`) ``x`` followed by a newline.
Examples
In the Julia programming language, the println
function is used to print the value of an expression followed by a newline character.
-
Print a string:
julia> println("Hello, World!") Hello, World!
This example prints the string
"Hello, World!"
and adds a newline character at the end. -
Print numerical values:
julia> x = 10 julia> y = 20 julia> println(x + y) 30
Here, the sum of
x
andy
is printed, resulting in30
. -
Print multiple values:
julia> a = 5 julia> b = 2.5 julia> c = "Julia" julia> println(a, " + ", b, " is ", c) 5 + 2.5 is Julia
In this example, the values of
a
,b
, andc
are printed along with some additional text.
Common mistake example:
julia> x = [1, 2, 3]
julia> println(x)
[1, 2, 3]
In this case, if you mistakenly pass an array to println
, it will print the array as a whole instead of printing its individual elements. If you want to print the elements separately, you can use the join
function or a loop to iterate over the array and print each element individually.
See Also
:@printf, :@sprintf, display, displayable, dump, info, isprint, print, println, print_escaped, print_joined, print_shortest, print_unescaped, print_with_color, pushdisplay, redisplay, show, showall, showcompact, sprint, versioninfo,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.