Function returning "(nothing, nothing,...)" after returning some strings

I am new to Julia and posting to forums so please excuse any bad formatting, I have some background with python so I have been trying to translate my python code to Julia which led me to being confused why this code is returning (nothing, nothing,…) after it returns what i wanted it to return

I was thinking it was due to the "println()"s but i went in and changed them to “print()” and added the \n inside it but it still prints out the same thing.

function sign()
ran = rand(1:2)  
if ran == 1
        return     (println(" ______     ______     __  __     ______    "),
    println("/\\___  \\   /\\  ___\\   /\\ \\/\\ \\   /\\  ___\\   "),
    println("\\/_/  /__  \\ \\  __\\   \\ \\ \\_\\ \\  \\ \\___  \\  "),
    println("  /\\_____\\  \\ \\_____\\  \\ \\_____\\  \\/\\_____\\ "),
    println("  \\/_____/   \\/_____/   \\/_____/   \\/_____/ "))
else
    return (println("    _/_/_/_/_/                                "),
    println("         _/      _/_/    _/    _/    _/_/_/   "),
    println("      _/      _/_/_/_/  _/    _/  _/_/        "),
    println("   _/        _/        _/    _/      _/_/     "),
    println("_/_/_/_/_/    _/_/_/    _/_/_/  _/_/_/        "))
end
end

sign()

Which returns this

Screenshot 2022-11-24 221848

The return value of print is nothing. This is conventional in Julia for functions used for their side effects, rather than their values.

Why are you calling print inside a return statement? That’s quite unusual in every language I’ve used, including Python.

2 Likes

I think your Python code should also return a tuple of None.

def sign():
    ...
    return (print("---"), print("___"), ..., )
1 Like

I’m not sure if I’ve understood the question. Does this do what you want?

function sign()
    ran = rand(1:2)  
    if ran == 1
        println(" ______     ______     __  __     ______    "),
        println("/\\___  \\   /\\  ___\\   /\\ \\/\\ \\   /\\  ___\\   "),
        println("\\/_/  /__  \\ \\  __\\   \\ \\ \\_\\ \\  \\ \\___  \\  "),
        println("  /\\_____\\  \\ \\_____\\  \\ \\_____\\  \\/\\_____\\ "),
        println("  \\/_____/   \\/_____/   \\/_____/   \\/_____/ ")
    else
        println("    _/_/_/_/_/                                "),
        println("         _/      _/_/    _/    _/    _/_/_/   "),
        println("      _/      _/_/_/_/  _/    _/  _/_/        "),
        println("   _/        _/        _/    _/      _/_/     "),
        println("_/_/_/_/_/    _/_/_/    _/_/_/  _/_/_/        ")
    end
    return
end
3 Likes