Scanln function can be used to take the input from the user in the Golang. Below is the example of taking input from the user:
Now save this file and execute as shown in the below screenshot:
Description About the Program:
- main Package: When we build reusable pieces of code, we will develop a package as a shared library. But when we develop an executable program, we will use the package “main” for making the package as an executable program. The package “main” tells the Golang compiler that the package should compile as an executable program instead of a shared library. The main function in the package “main” will be the entry point of our executable program. Remember when we build shared libraries, we will not have any main package and main function in the package.
- fmt.Println is the print function which is used to print the output in the next line. While fmt.Print is used to display output in the same line. Whatever needs to be printed has to be written in inverted commas ” “.
- var first string is the declaration of the variable first which is of string type. To declare variables following syntax needs to be followed:
var var_name data_type
- fmt.Scanln(&first) is used to take input from user in the next line. While fmt.Scan is used to take input from user in the same line. Ampersand is necessary to give the reference as to in which variable we have to store the variable.
- The Last line will simply add the two string of First Name and Last Name and will output the Full Name.
- Take Matrix input from user in Python
- How to take user input for two dimensional (2D) array in PHP ?
- How to validate and sanitize user input with PHP?
- Taking Input from User in R Programming
- DelayQueue take() method in Java with Examples
- What is Hactoberfest and How One Can Take Participate in it?
- How to take screenshots on MacBook?
- How to make the cursor to hand when a user hovers over a list item using CSS?
- How to create an unordered_map of user defined class in C++?
- HTTP headers | User-Agent
- How to create an unordered_set of user defined class or struct in C++?
- CSS | User Interface
- How to create a Java HashMap of user defined class type?
- How to read a Matrix from user in Java?
- How to hide a div when the user clicks outside of it using jQuery?
- How to create a user defined javap tool?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.