{"id":9818,"date":"2022-08-17T12:23:48","date_gmt":"2022-08-17T12:23:48","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=9818"},"modified":"2024-04-15T09:43:39","modified_gmt":"2024-04-15T09:43:39","slug":"go-data-type-understanding-data-types-in-go","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/go-lang\/go-data-type-understanding-data-types-in-go\/","title":{"rendered":"Go Data Type"},"content":{"rendered":"<h2><span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Understanding Data Types in Go&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:513,&quot;3&quot;:{&quot;1&quot;:0},&quot;12&quot;:0}\">Understanding Data Types in Go<\/span><\/h2>\n<p>&nbsp;<\/p>\n<p><strong>Go has <a href=\"https:\/\/go.dev\/\">three<\/a> basic <a href=\"https:\/\/prwatech.in\/blog\/go-lang\/installation-of-go-windows\/\">data<\/a> types:<\/strong><\/p>\n<ol>\n<li><strong>Bool <\/strong><\/li>\n<li><strong>Numerical<\/strong><\/li>\n<li><strong>String<\/strong><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li>This program shows some of the different data types in Go\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">package main\r\nimport \"fmt\"\r\n\r\nfunc main() {\r\n\tvar a bool = true          \/\/ Boolean\r\n\tvar b int = 5              \/\/ Integer\r\n\tvar c float32 = 6.14       \/\/ Floating point number\r\n\tvar d string = \"PRWATECH!\" \/\/ String\r\n\r\n\tfmt.Println(\"Boolean: \", a)\r\n\tfmt.Println(\"Integer: \", b)\r\n\tfmt.Println(\"Float:   \", c)\r\n\tfmt.Println(\"String:  \", d)\r\n}\t\r\n<\/pre>\n<p>Output :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">PS C:\\GO_Language\\datatype&gt; go run type.go\r\nBoolean:  true\r\nInteger:  5\r\nFloat:    6.14\r\nString:   PRWATECH!\r\n<\/pre>\n<\/li>\n<li><strong>Boolean data type: <\/strong>datatype is declared with the bool keyword and can take the values <strong>true<\/strong> or <strong>false<\/strong>.\n<ol>\n<li>This program shows some different ways to declare Boolean variables:\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">package main\r\nimport \"fmt\"\r\nfunc main() {\r\n    var b1 bool = true\r\n    var b2 = true\r\n    var b3 bool\r\n    b4 := true\r\n    fmt.Println(b1)\r\n    fmt.Println(b2)\r\n    fmt.Println(b3)\r\n    fmt.Println(b4)\r\n}\r\n<\/pre>\n<p>Output :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">PS C:\\GO_Language\\datatype&gt; go run bool.go\r\ntrue\r\ntrue\r\nfalse\r\ntrue\r\n<\/pre>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>Integer data type: <\/strong>are used to store a whole no. without decimals, like 35.50.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>Integer has two types:<\/strong>\n<ol>\n<li>Signed integers<\/li>\n<li>Unsigned integers<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong>Singed integer:<\/strong><\/li>\n<\/ul>\n<p>Signed integers, declared with one of the\u00a0int\u00a0keywords, can store both positive and negative values<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">package main\r\n\r\nimport \"fmt\"\r\n\r\nfunc main() {\r\n    var x int = 50\r\n    var y int = 40\r\n    fmt.Printf(\"Type: %T, value: %v \\n\", x, x)\r\n    fmt.Printf(\"Type: %T, value: %v\", y, y)\r\n}\r\n<\/pre>\n<p>Output :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">PS C:\\GO_Language\\datatype&gt; go run int1.go\r\nType: int, value: 50 \r\nType: int, value: 40\r\n<\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ul>\n<li><strong>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0Unsigned integers:<\/strong><\/li>\n<\/ul>\n<p>Unsigned integers, declared with one of the\u00a0uint\u00a0keywords, can only store non-negative values:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">package main\r\nimport \"fmt\"\r\n\r\nfunc main() {\r\n    var x uint = 50\r\n    var y uint = 450\r\n\r\n    fmt.Printf(\"Type: %T, value: %v \\n\", x, x)\r\n    fmt.Printf(\"Type: %T, value: %v\", y, y)\r\n}\r\n\r\n<\/pre>\n<p>Output :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">PS C:\\GO_Language\\datatype&gt; go run int2.go\r\n  \r\nType: uint, value: 50 \r\nType: uint, value: 450\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>3)<strong>float data type:<\/strong><\/p>\n<p><strong>\u00a0<\/strong>are used to store positive and negative no. which a decimal point, like 35.3, -32, to 3423.243525.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><strong>Type\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 size\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Range<\/strong><\/p>\n<p>Float32\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 32bits\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -34e+38 to 3.4e+38.<\/p>\n<p>Float64\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 64bits\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -1.7e+308 to 3.4e+308.<\/p>\n<p>This program shows how to declare some variables of type\u00a0float32:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">package main\r\n\r\nimport \"fmt\"\r\n\r\nfunc main() {\r\n    var x float32 = 23.78\r\n    var y float32 = 3.4e+38\r\n\r\n    fmt.Printf(\"Type: %T, value: %v\\n\", x, x)\r\n    fmt.Printf(\"Type: %T, value: %v\", y, y)\r\n}\r\n<\/pre>\n<p>output :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">PS C:\\GO_Language\\datatype&gt; go run float1.go\r\n  \r\nType: float32, value: 23.78\r\nType: float32, value: 3.4e+38\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>This Progeam shows how to declare a variable of type\u00a0float64:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">package main\r\nimport \"fmt\"\r\n\r\nfunc main() {\r\n    var x float64 = 1.7e+308\r\n    \r\n    fmt.Printf(\"Type: %T, value: %v\", x, x)\r\n    \r\n}\r\n<\/pre>\n<p>check output :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">PS C:\\GO_Language\\datatype&gt; go run float2.go\r\n   \r\nType: float64, value: 1.7e+308\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>3)String Data type: <\/strong>the string datatype is use to store a sequence of characters. String values must be surround by double quotes:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">package main\r\n\r\nimport \"fmt\"\r\n\r\nfunc main() {\r\n    var txt1 string = \"parwatech\"\r\n    var txt2 string\r\n    txt3 := \"World 1\"\r\n\r\n    fmt.Printf(\"Type: %T, value: %\\n\", txt1, txt1)\r\n    fmt.Printf(\"Type: %T, value: %v\\n\", txt2, txt2)\r\n    fmt.Printf(\"Type: %T, value: %v\\n\", txt3, txt3)\r\n}\r\n<\/pre>\n<p>output:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">PS C:\\GO_Language\\datatype&gt; go run str.go   \r\n \r\nType: string, value: parwatech \r\nType: string, value:  \r\nType: string, value: World 1\r\n<\/pre>\n<p>Understanding Data Types in Go<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Understanding Data Types in Go &nbsp; Go has three basic data types: Bool Numerical String &nbsp; This program shows some of the different data types in Go package main import &#8220;fmt&#8221; func main() { var a bool = true \/\/ Boolean var b int = 5 \/\/ Integer var c float32 = 6.14 \/\/ Floating [&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":[2023,1560,1557,2022,1558,1559],"class_list":["post-9818","post","type-post","status-publish","format-standard","hentry","category-go-lang","category-golang-modules","tag-an-introduction-to-gos-basic-syntax-and-data-types","tag-bool","tag-go-datatypes","tag-how-to-find-the-type-of-a-variable-in-golang","tag-integer","tag-numerical"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Understanding Data Types in Go - Prwatech<\/title>\n<meta name=\"description\" content=\"Master Understanding Data Types in Go - 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=\"Understanding Data Types in Go - Prwatech\" \/>\n<meta property=\"og:description\" content=\"Master Understanding Data Types in Go - Dive deep with our expert instructors and comprehensive curriculum.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/go-lang\/go-data-type-understanding-data-types-in-go\/\" \/>\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-17T12:23:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-15T09:43:39+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=\"1 minute\" \/>\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-data-type-understanding-data-types-in-go\/\",\"url\":\"https:\/\/prwatech.in\/blog\/go-lang\/go-data-type-understanding-data-types-in-go\/\",\"name\":\"Understanding Data Types in Go - Prwatech\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"datePublished\":\"2022-08-17T12:23:48+00:00\",\"dateModified\":\"2024-04-15T09:43:39+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Master Understanding Data Types in Go - Dive deep with our expert instructors and comprehensive curriculum.\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/go-lang\/go-data-type-understanding-data-types-in-go\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/go-lang\/go-data-type-understanding-data-types-in-go\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/go-lang\/go-data-type-understanding-data-types-in-go\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Data Type\"}]},{\"@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":"Understanding Data Types in Go - Prwatech","description":"Master Understanding Data Types in Go - 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":"Understanding Data Types in Go - Prwatech","og_description":"Master Understanding Data Types in Go - Dive deep with our expert instructors and comprehensive curriculum.","og_url":"https:\/\/prwatech.in\/blog\/go-lang\/go-data-type-understanding-data-types-in-go\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2022-08-17T12:23:48+00:00","article_modified_time":"2024-04-15T09:43:39+00:00","author":"Prwatech","twitter_card":"summary_large_image","twitter_creator":"@Eduprwatech","twitter_site":"@Eduprwatech","twitter_misc":{"Written by":"Prwatech","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/go-lang\/go-data-type-understanding-data-types-in-go\/","url":"https:\/\/prwatech.in\/blog\/go-lang\/go-data-type-understanding-data-types-in-go\/","name":"Understanding Data Types in Go - Prwatech","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"datePublished":"2022-08-17T12:23:48+00:00","dateModified":"2024-04-15T09:43:39+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Master Understanding Data Types in Go - Dive deep with our expert instructors and comprehensive curriculum.","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/go-lang\/go-data-type-understanding-data-types-in-go\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/go-lang\/go-data-type-understanding-data-types-in-go\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/go-lang\/go-data-type-understanding-data-types-in-go\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Data Type"}]},{"@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\/9818","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=9818"}],"version-history":[{"count":9,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/9818\/revisions"}],"predecessor-version":[{"id":11522,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/9818\/revisions\/11522"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=9818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=9818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=9818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}