Golang fmt.Println() Function with Examples (2024)

  • Home
  • DS & Algo. ▾
    • Data Structure
    • Algorithms
    • Coding Problems
  • Languages ▾
    • C
    • C++
    • C++ STL
    • Java
    • Python
    • Scala
    • Ruby
    • C#.Net
    • Golang
    • Android
    • Kotlin
    • SQL
  • Web. ▾
    • JavaScript
    • CSS
    • jQuery
    • PHP
    • Node.Js
    • AdonisJs
    • VueJS
    • Ajax
    • HTML
    • Django
  • Programs ▾
    • C
    • C++
    • Data Structure
    • Java
    • C#.Net
    • VB.Net
    • Python
    • PHP
    • Golang
    • Scala
    • Swift
    • Rust
    • Ruby
    • Kotlin
    • C Interview Programs
  • Aptitude ▾
    • C Aptitude
    • C++ Aptitude
    • Java Aptitude
    • C# Aptitude
    • PHP Aptitude
    • Linux Aptitude
    • DBMS Aptitude
    • Networking Aptitude
    • AI Aptitude
    • More...
  • Interview ▾
    • Golang
    • MIS Executive
    • DBMS
    • C
    • Embedded C
    • Java
    • SEO
    • HR
  • Find Output ▾
    • C
    • C++
    • C#.Net
    • Java
    • Go
    • PHP
    • More...
  • MCQs ▾
    • Web Technologie MCQs
    • CS Subjects MCQs
    • Databases MCQs
    • Programming MCQs
    • Testing Software MCQs
    • Digital Mktg Subjects MCQs
    • Cloud Computing S/W MCQs
    • Engineering Subjects MCQs
    • Commerce MCQs
    • More MCQs...
  • CS Subjects ▾
    • Machine Learning/AI
    • Operating System
    • Computer Network
    • Software Engineering
    • Discrete Mathematics
    • Digital Electronics
    • Data Mining
    • MIS
    • DBMS
    • Embedded Systems
    • Cryptography
    • CS Fundamental
    • More Tutorials...
  • More ▾
    • Tech Articles
    • Puzzles
    • Full Forms
    • Code Examples
    • Blogs
    • Guest Post
    • Programmer's Calculator
    • XML Sitemap Generator
    • About
    • Contact

×

Golang Tutorial

  • Golang - Home
  • Golang - Keywords
  • Golang - Data Types
  • Golang - Variables
  • Golang - Constants
  • Golang - Program Structure
  • Golang - Comments
  • Golang - Naming a variable
  • Golang - Shorthand for Defining Multiple Variables/Constants
  • Golang - Find Type of Variable
  • Golang - Binary Literals
  • Golang - Octal Literals
  • Golang - Hexadecimal Literals
  • Golang - Type Casting or Type Conversion
  • Golang – Operators
  • Golang - Arithmetic Operators
  • Golang - Relational Operators
  • Golang - Logical Operators
  • Golang - Bitwise Operators
  • Golang - Assignment Operators
  • Golang - Miscellaneous Operators
  • Golang - if statement
  • Golang - if-else statement
  • Golang - if-else-if ladder statement
  • Golang - nested if statement
  • Golang - switch statement
  • Golang - select statement
  • Golang - Loops
  • Golang - Functions
  • Golang - Strings

Golang Reference

  • Go - builtin Package
  • Go - bytes Package
  • Go - fmt Package
  • Go - math Package
  • Go - os Package
  • Go - sort Package
  • Go - strconv Package
  • Go - strings Package
  • Go - unicode Package

Golang Programs

  • Golang Programs - Home
  • Golang - Basic Programs
  • Golang - Switch Statement Programs
  • Golang - goto Statement Programs
  • Golang - Looping Programs
  • Golang - Array Programs
  • Golang - String Programs
  • Golang - Structure Programs
  • Golang - User-defined Function Programs
  • Golang - Variadic Function Programs
  • Golang - Recursion Programs
  • Golang - Pointer Programs
  • Golang - Conversion Programs
  • Golang - Slices Programs
  • Golang - Goroutines Programs
  • Golang - Reflection Programs
  • Golang - Maps Programs
  • Golang - Range Programs
  • Golang - Channels Programs
  • Golang - File Handling Programs
  • Golang - Buffered Input-Output Programs
  • Golang - Command-line Arguments Programs
  • Golang - Regular Expressions Programs
  • Golang - JSON Programs
  • Golang - os Package Programs
  • Golang - strconv Package Programs
  • Golang - log Package Programs
  • Golang - math/rand Package Programs
  • Golang - math/bits Package Programs
  • Golang - sync/atomic Package Programs
  • Golang - path/filepath Package Programs
  • Golang - syscall Package Programs
  • Golang - Signals Programs
  • Golang - Shell Script Programs

Golang Practice

  • Golang Interview Questions
  • Golang Programs
  • Golang Find Output Programs
  • Golang Aptitude Questions
  • Go FAQ

Golang Miscellaneous

  • Golang - Print Boolean Value
  • Golang - Print Double-quoted String
  • Golang - Convert From Int to Binary
  • Golang - Convert From Int to Octal
  • Golang - Convert From Int to Hex
  • Golang - Check if Structure is Empty
  • Golang - Check if Key Exists in Map
  • Golang - Return an Error

Home »Golang »Golang Reference

Golang | fmt.Println() Function: Here, we are going to learn about the Println() function of the fmt package with its usages, syntax, and examples.
Submitted by IncludeHelp, on October 09, 2021

fmt.Println()

In Go language, the fmt package implements formatted I/O with functions analogous to C's printf() and scanf(). The Println() function is an inbuilt function of the fmt package which is used to format using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended.

It accepts one parameter (a ...interface{}) and returns the number of total bytes written and an error if occurred during the write operation.

Syntax:

func Println(a ...interface{}) (n int, err error)

Parameter(s):

  • a : A custom type that is used to specify a set of one or more method signatures, here we can provide a set of the variables, constants, functions, etc.

Return Value:

The return type of the fmt.Println() function is (n int, err error), it returns the number of total bytes written and an error if occurred during the write operation.

Example 1:

// Golang program to demonstrate the// example of fmt.Println() functionpackage mainimport ("fmt")func main() {// Printing simple textn, err := fmt.Println("Hello, world!")// fmt.Println() returns:// n - Number of printed characters// err - Error (if any)fmt.Println(n, "Characters printed.")fmt.Println("Error: ", err)}

Output:

Hello, world!14 Characters printed.Error: <nil>

Example 2:

// Golang program to demonstrate the// example of fmt.Println() functionpackage mainimport ("fmt")func main() {// Print text with new linefmt.Println("Hello World")fmt.Println("Hi, there...")// Printing text, values togetherfmt.Println("Name: ", "Alex", " Age: ", 21)// Printing variable values// Declaring & assigning variablesvar (name stringage intperc float32)name = "Alex"age = 21perc = 87.5// Printingfmt.Println("Name: ", name, " Age: ", age, " Perc: ", perc)}

Output:

Hello WorldHi, there...Name: Alex Age: 21Name: Alex Age: 21 Perc: 87.5

Example 3:

// Golang program to demonstrate the// example of fmt.Println() functionpackage mainimport ("fmt")func main() {name := "Dev"age := 21city := "New York"// Printing using fmt.Printf()fmt.Println("Hey I'm ", name, " ", age, "years old.")fmt.Println("I live in ", city)}

Output:

Hey I'm Dev 21 years old.I live in New York

Golang fmt Package »

Golang fmt.Printf() Function

Golang fmt.Scan() Function

Comments and Discussions!

Load comments ↻


Golang fmt.Println() Function with Examples (2024)

References

Top Articles
Latest Posts
Article information

Author: Errol Quitzon

Last Updated:

Views: 5801

Rating: 4.9 / 5 (79 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Errol Quitzon

Birthday: 1993-04-02

Address: 70604 Haley Lane, Port Weldonside, TN 99233-0942

Phone: +9665282866296

Job: Product Retail Agent

Hobby: Computer programming, Horseback riding, Hooping, Dance, Ice skating, Backpacking, Rafting

Introduction: My name is Errol Quitzon, I am a fair, cute, fancy, clean, attractive, sparkling, kind person who loves writing and wants to share my knowledge and understanding with you.