{"id":9796,"date":"2022-08-11T09:39:18","date_gmt":"2022-08-11T09:39:18","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=9796"},"modified":"2024-04-15T09:35:40","modified_gmt":"2024-04-15T09:35:40","slug":"go-output-function-how-to-define-and-call-a-function-in-golang","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/go-lang\/go-output-function-how-to-define-and-call-a-function-in-golang\/","title":{"rendered":"Go output function"},"content":{"rendered":"<h2><span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;How to Define and Call a Function in Golang&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:513,&quot;3&quot;:{&quot;1&quot;:0},&quot;12&quot;:0}\">How to Define and Call a Function in Golang<\/span><\/h2>\n<p>&nbsp;<\/p>\n<p>In Go (or Golang), defining and calling functions is fundamental to structuring and organizing code. Functions in Go are declared using the <code>func<\/code> keyword followed by the function name, parameters (if any), return types (if any), and the function body enclosed in curly braces. Functions can be defined at package level or within other functions, allowing for modular and reusable code.<\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li>\n<h4><strong>Go has <a href=\"https:\/\/prwatech.in\/blog\/go-lang\/installation-of-go-windows\/\">three<\/a> output <a href=\"https:\/\/go.dev\/\">functions<\/a>:<\/strong><\/h4>\n<\/li>\n<\/ul>\n<ol>\n<li><strong>Print()<\/strong><\/li>\n<li><strong>Println()<\/strong><\/li>\n<li><strong>Printf()<\/strong><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><strong>1) Print():<\/strong> function print its arguments with the default format.<\/p>\n<p>&nbsp;<\/p>\n<ol>\n<li>\u00a0Program to illustrate print function.\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">package main\r\n\r\nimport \"fmt\"\r\n\r\nfunc main() {\r\n    var i, j string = \"Prwa\", \"tech\"\r\n\r\n    fmt.Print(i)\r\n    fmt.Print(j)\r\n\r\n}\r\n<\/pre>\n<p>Output :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">PS C:\\GO_Language\\output&gt; go run output1.go\r\nPrwa Tech\r\n<\/pre>\n<\/li>\n<li>Program to illustrate print function in new line using \u201c<strong>\\n<\/strong>\u201d.\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">package main\r\n\r\nimport \"fmt\"\r\n\r\nfunc main() {\r\n    var i, j string = \"Data\", \"Science\"\r\n\r\n    fmt.Print(i, \"\\n\")\r\n    fmt.Print(j, \"\\n\")\r\n}\r\n<\/pre>\n<p>Output :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">PS C:\\GO_Language\\output&gt; go run output2.go\r\nData\r\nScience\r\n<\/pre>\n<\/li>\n<li>Program to illustrate print function in a line using \u201c<strong>\\n<\/strong>\u201d.\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">package main\r\n\r\nimport \"fmt\"\r\n\r\nfunc main() {\r\n    var i, j string = \"Data\", \"Science\"\r\n\r\n    fmt.Print(i, \"\\n\", j)\r\n}\r\n<\/pre>\n<p>Output :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">PS C:\\GO_Language\\output&gt; go run output3.go\r\nPython \r\nMachine Learning\r\n<\/pre>\n<\/li>\n<li>Program to represent the print function of integer values.\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">package main\r\n\r\nimport \"fmt\"\r\n\r\nfunc main() {\r\n    var i, j = 10, 20\r\n\r\n    fmt.Print(i, j)\r\n}\r\n<\/pre>\n<p>Output :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">PS C:\\GO_Language\\output&gt; go run output4.go\r\n10  20\r\n<\/pre>\n<p>&nbsp;<\/li>\n<\/ol>\n<p>2) <strong>println(): <\/strong>whitespace is added between the arguments, and a newline is added at the end:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">package main\r\nimport \"fmt\"\r\n\r\nfunc main() {\r\n    var i, j string = \"Parwa\", \"Tech\"\r\n    fmt.Println(i, j)\r\n}\r\n<\/pre>\n<p>Output :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">PS C:\\GO_Language\\output&gt; go run output5.go    \r\nParwa Tech\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>3) Printf(): <\/strong>first formats its arguments based on the given formatting verb and then print them.<\/p>\n<p><strong>%v \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/strong>use to print the value of the arguments<\/p>\n<p><strong>%T \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/strong>used to print the type of the arguments<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">package main\r\n\r\nimport \"fmt\"\r\n\r\nfunc main() {\r\n    var i string = \"PRWATECH\"\r\n    var j int = 10\r\n\r\n    fmt.Printf(\"i has value: %v and type: %T\\n\", i, i)\r\n    fmt.Printf(\"j has value: %v and type: %T\", j, j)\r\n}\r\n<\/pre>\n<p>Output:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">PS C:\\GO_Language\\output&gt; go run op6.go\r\n  \r\ni has value: PRWATECH and type: string\r\nj has value: 10 and type: int\r\n<\/pre>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong>Formatting Verb for Printf()<\/strong><\/li>\n<\/ul>\n<table>\n<tbody>\n<tr>\n<td width=\"264\"><strong>Verb<\/strong><\/td>\n<td width=\"349\"><strong>Description<\/strong><\/p>\n<p><strong>\u00a0<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"264\"><strong>%v<\/strong><\/td>\n<td width=\"349\">Print the value in the default format<\/td>\n<\/tr>\n<tr>\n<td width=\"264\"><strong>%#v<\/strong><\/td>\n<td width=\"349\">Print the value in Go syntax format<\/td>\n<\/tr>\n<tr>\n<td width=\"264\"><strong>%T<\/strong><\/td>\n<td width=\"349\">Print the type of the value<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>5. Program to illustrate printf function of verbs can be use with all data types.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">package main\r\nimport \"fmt\"\r\nfunc main() {\r\n    var i = 10.5\r\n    var X = \"PRWATECH\"\r\n\r\n    fmt.Printf(\"%v\\n\", i)\r\n    fmt.Printf(\"%#v\\n\", i)\r\n    fmt.Printf(\"%v%%\\n\", i)\r\n    fmt.Printf(\"%T\\n\", i)\r\n\r\n    fmt.Printf(\"%v\\n\", X)\r\n    fmt.Printf(\"%#v\\n\", X)\r\n    fmt.Printf(\"%T\\n\", X)\r\n}\r\n<\/pre>\n<p>Output :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">PS C:\\GO_Language\\output\\p&gt; go run printf1.go\r\n10.5\r\n10.5\r\n10.5%\r\nfloat64\r\nPRWATECH\r\n\"PRWATECH\"\r\nstring\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>6. Program to illustrate printf function of verbs can be use with integer data types.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">package main\r\nimport \"fmt\"\r\nfunc main() {\r\n    var i = 10\r\n\r\n    fmt.Printf(\"%b\\n \", i)\r\n    fmt.Printf(\"%d\\n \", i)\r\n    fmt.Printf(\"%+d\\n \", i)\r\n    fmt.Printf(\"%o\\n \", i)\r\n    fmt.Printf(\"%O\\n \", i)\r\n    fmt.Printf(\"%x\\n \", i)\r\n    fmt.Printf(\"%X\\n \", i)\r\n    fmt.Printf(\"%#x\\n \", i)\r\n    fmt.Printf(\"%4d\\n \", i)\r\n    fmt.Printf(\"%-4d\\n \", i)\r\n    fmt.Printf(\"%04d\\n \", i)\r\n}\r\n<\/pre>\n<p>Output :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">PS C:\\GO_Language\\output\\p&gt; go run printf2.go\r\n1010\r\n 10\r\n +10\r\n 12\r\n 0o12\r\n a\r\n A\r\n 0xa\r\n   10\r\n 10  \r\n 0010\r\n<\/pre>\n<p>How to Define and Call a Function in Golang<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to Define and Call a Function in Golang &nbsp; In Go (or Golang), defining and calling functions is fundamental to structuring and organizing code. Functions in Go are declared using the func keyword followed by the function name, parameters (if any), return types (if any), and the function body enclosed in curly braces. Functions [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[666,1707],"tags":[812,808,2019,2018],"class_list":["post-9796","post","type-post","status-publish","format-standard","hentry","category-go-lang","category-golang-modules","tag-go-lang-tutorial","tag-go-language","tag-how-to-define-and-call-a-function-in-golang","tag-working-with-functions-in-go"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Define and Call a Function in Golang - Prwatech<\/title>\n<meta name=\"description\" content=\"Master How to Define and Call a Function in Golang - Dive deep with our expert instructors and comprehensive curriculum.\" \/>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Define and Call a Function in Golang - Prwatech\" \/>\n<meta property=\"og:description\" content=\"Master How to Define and Call a Function in Golang - Dive deep with our expert instructors and comprehensive curriculum.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/go-lang\/go-output-function-how-to-define-and-call-a-function-in-golang\/\" \/>\n<meta property=\"og:site_name\" content=\"Prwatech\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prwatech.in\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-11T09:39:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-15T09:35:40+00:00\" \/>\n<meta name=\"author\" content=\"Prwatech\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:site\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prwatech\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prwatech.in\/blog\/go-lang\/go-output-function-how-to-define-and-call-a-function-in-golang\/\",\"url\":\"https:\/\/prwatech.in\/blog\/go-lang\/go-output-function-how-to-define-and-call-a-function-in-golang\/\",\"name\":\"How to Define and Call a Function in Golang - Prwatech\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"datePublished\":\"2022-08-11T09:39:18+00:00\",\"dateModified\":\"2024-04-15T09:35:40+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Master How to Define and Call a Function in Golang - Dive deep with our expert instructors and comprehensive curriculum.\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/go-lang\/go-output-function-how-to-define-and-call-a-function-in-golang\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/go-lang\/go-output-function-how-to-define-and-call-a-function-in-golang\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/go-lang\/go-output-function-how-to-define-and-call-a-function-in-golang\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go output function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/prwatech.in\/blog\/#website\",\"url\":\"https:\/\/prwatech.in\/blog\/\",\"name\":\"Prwatech\",\"description\":\"Share Ideas, Start Something Good.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/prwatech.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\",\"name\":\"Prwatech\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"caption\":\"Prwatech\"},\"url\":\"https:\/\/prwatech.in\/blog\/author\/prwatech123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Define and Call a Function in Golang - Prwatech","description":"Master How to Define and Call a Function in Golang - Dive deep with our expert instructors and comprehensive curriculum.","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"How to Define and Call a Function in Golang - Prwatech","og_description":"Master How to Define and Call a Function in Golang - Dive deep with our expert instructors and comprehensive curriculum.","og_url":"https:\/\/prwatech.in\/blog\/go-lang\/go-output-function-how-to-define-and-call-a-function-in-golang\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2022-08-11T09:39:18+00:00","article_modified_time":"2024-04-15T09:35:40+00:00","author":"Prwatech","twitter_card":"summary_large_image","twitter_creator":"@Eduprwatech","twitter_site":"@Eduprwatech","twitter_misc":{"Written by":"Prwatech","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/go-lang\/go-output-function-how-to-define-and-call-a-function-in-golang\/","url":"https:\/\/prwatech.in\/blog\/go-lang\/go-output-function-how-to-define-and-call-a-function-in-golang\/","name":"How to Define and Call a Function in Golang - Prwatech","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"datePublished":"2022-08-11T09:39:18+00:00","dateModified":"2024-04-15T09:35:40+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Master How to Define and Call a Function in Golang - Dive deep with our expert instructors and comprehensive curriculum.","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/go-lang\/go-output-function-how-to-define-and-call-a-function-in-golang\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/go-lang\/go-output-function-how-to-define-and-call-a-function-in-golang\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/go-lang\/go-output-function-how-to-define-and-call-a-function-in-golang\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Go output function"}]},{"@type":"WebSite","@id":"https:\/\/prwatech.in\/blog\/#website","url":"https:\/\/prwatech.in\/blog\/","name":"Prwatech","description":"Share Ideas, Start Something Good.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/prwatech.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3","name":"Prwatech","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","caption":"Prwatech"},"url":"https:\/\/prwatech.in\/blog\/author\/prwatech123\/"}]}},"_links":{"self":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/9796","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/comments?post=9796"}],"version-history":[{"count":6,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/9796\/revisions"}],"predecessor-version":[{"id":11520,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/9796\/revisions\/11520"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=9796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=9796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=9796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}