In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "Introduction to Basic Data Types in Go Language". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "Introduction to Basic Data Types in Go Language"!
Go is a statically typed programming language in which data types are used to declare functions and variables. The emergence of data types is to divide data into different memory sizes required, programming needs to use large data when it is necessary to apply for large memory, you can make full use of memory.
boolean
There are only two types of Boolean values: true or false. The conditional parts of if and for statements are Boolean values, and comparison operations such as == and Unary operator! The logic does not work, therefore! True is false, and a more complex form is (! true==false) == true, in practice we should try to use a simpler Boolean expression, just like using x to represent x==true. var a = 10fmt.Println(a == 10) // truefmt.Println(a == 5) // falsefmt.Println(a != 10) // falsefmt.Println(a != 5) // true Go has very strict restrictions on comparing values; only two values of the same type can be compared, and if the value type is interface, they must both implement the same interface. If one of the values is constant, the other value may not be constant, but it must be of the same type as the constant. If none of the above conditions are met, one value must be converted to the same type as the other before comparison can be made. var a = 10fmt.Println(a == true) // cannot use true (type untyped bool) as type int Boolean values can sum &&(AND) and|| (OR) operators combine and have short-circuit behavior. If the value on the left of the operator can already determine the value of the entire Boolean expression, then the value on the right of the operator will no longer be evaluated, so the following expression is always safe: s != "" && s[0] == 'x' Go does not allow integer to be coerced into boolean, so the code is as follows: var n boolfmt.Println(int(n) * 2) // cannot convert n (type bool) to type int numeric Go's numeric types are divided into the following categories: integers, floating-point numbers, and complex numbers. For example, signed integers include int8, int16, int32, int64, etc. Each numeric type determines the corresponding size range and whether positive and negative signs are supported. In this section, we focus on numerical types. integer Go is also architecture-based, providing both signed and unsigned integer types. In most cases, we only need int, which can be used for loop counters (variables that control the number of loops in a for loop), indexes of arrays and slices, and any general-purpose integer operator. int is usually the fastest type to process. floating-point Go provides floating-point numbers in two precision classes: float32 and float64, which can range from tiny to huge. plural A complex number is represented by two floating-point numbers, one representing the real part and one representing the imaginary part. There are two types of complex numbers in Go: complex128 (64-bit real and imaginary) and complex64 (32-bit real and imaginary), with complex128 being the default type for complex numbers. The value of a complex number consists of three parts RE + IMi, where RE is the real part, IM is the imaginary part, RE and IM are both of float type, and the last i is the imaginary unit. 1+2i string type String is a value type, and the value is immutable, that is, after creating a text will not be able to modify the content of this text again, in fact, string is a fixed-length array of bytes. Use double quotes "" to define strings. Escape characters can be used in strings to achieve newline, indentation and other effects. Common escape characters include: \n: newline \r: carriage return \t: tab key \u or\U`: Unicode characters \\: backslash itself Go is much more flexible than other languages, and multiline strings can be defined by using backquotes. (Note: it's backquotes `(left key of key 1 on keyboard), not quotes') At this point, I believe that everyone has a deeper understanding of "Introduction to Basic Data Types in Go Language", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.