How to take user input in Julia?

Users can interact with the program and provide dynamic values to the variables with the help of inputs. In this answer, we'll learn to take input from the user in Julia.

Julia provides below two methods to take user input from the console.

  • readline(): This method will read one line of user input as a string from the STDINStandard input and output console.

  • readlines(): This method will read the multiline of user input as a vector of strings from the STDINStandard input and output console.

Syntax

# syntax for single line input from the user
readline()
# syntax for multiline input from the user
readlines()

Example for a single line input

println("Enter your name: ")
#Take single line user input from the user
user_name = readline()
println("Hello $user_name from Educative 😊")

Enter the input below

Code explanation

  • Line 4: We take the user name as input from the STDIN console using the I/O method readline(), and assign value to a variable user_name.

  • Line 6: We print a message including the user name input value user_name.

Example for multiple lines input

println("Enter your toppings: ")
#Take multiline input from the user
toppings = readlines()
println("You have provided below toppings.")
println(toppings)

Enter the input below

Code explanation

  • Line 4: We take the toppings as input from the STDIN console using the I/O method readlines(), and assign value to a variable toppings.

  • Line 7: We display the toppings, toppings.

Free Resources

Copyright Β©2026 Educative, Inc. All rights reserved