Go is similar to PhP, and the end of each line should be added to the end. The difference is that go is not compatible with this, and this point is like JavaScript, in addition, the upper sentence of Go is enclosed by a large bag, but go requires that the upper left corner must be at the end of the upper sentence, this is a new feature, at least for the first time in my response to the program. the other thing is that go is sensitive to large and small objects. I believe there will be no suggestions for this.
In the go statement, the encoding method is the same as that in PHP. For a single line, the encoding method is //, while for multiple lines, the/* encoding internal content */is used */, there is no difference in this.
Go has the numeric int type specified by the kernel. This type is very special. It will automatically determine the maximum length of your hardware, on 32-bit hardware, his length is 32-bit. On 64-bit hardware, his length is 64-bit. Of course, you can also define the length of a variable, such as int8, int16, int32, int64, byte, uint8, uint16, uint32, and uint64. Note that the bytes here are the unique bytes of uint8.
Float32 and float64
The numeric type is represented by the constants true and false of the scalar definition. The definite method is Var x bool = true;
Go native supports batch data, and the variable type is complex128; complex64; complex32
In addition, there are several special types, such as error and uintptr, which will be used for further discussion.
Do not mix these types as many as possible. If you do not mix these types, they will generate a response. Let's look at the generation of the response:
package main func main() { var a int var b int32 a = 15 b = a + a b = b + 5 }
This generation is a mix of data types. Therefore, when the generation is complete, if you want to keep him offline, you must use the dynamic data processing function to discuss this part in the future.
There are many ways to change the definition of Go statement. In fact, there should be only two methods. The first method is:
VaR variable name type = initial value
For example:
VaR A Int = 123
The type can also be omitted.
VaR A = 123
This method is mainly used to define global variation. In fact, it can extend many different kinds of transformation methods, such
var( a int b bool c,d string = "abc","ff" )
In practice, only one method can be used. Other different methods can only recognize what he is doing, there is no need to remember every one.
The above is the first definition method. In fact, there is another definition method that is more explicit. However, this definition method can only be used within the function, the algorithm is as follows:
A: 123
A, B: = 20, 16
_, B: = 34, 35
In the go statement, there is a special change, that is, the _ parameter set by the system. All the values assigned to this change will be automatically deleted, this is because the go statement does not allow the variable volume to be used. Once this variable volume cannot be used, you can add a value.
We have learned from the previous article that the packages imported from the import will be released if they are not used, here we understand that if the variable quantity is not useful, it will be helpful. We can see the intention of the Go statement, I think these two features are very good. it requires programmers to write their programs. I am very pleased with this.
Variable definition only has so many things. You just need to grasp a few points, that is, outside function, if you want to define a variable, you can only use VaR to define it, the parameter format cannot be: = Because: = can only be used within the function.
Constant definition is almost the same as variable definition. It just converts var into const definition, in addition, I have an additional parameter type iota. Let's look at the example below:
Const (
A = iota
B = iota
)
The value of A is 0 when I first give a valid value, and the value of B is 1 when I give B a valid value for the second time.
Here I specifically describe the string type. This type is the class type set in the go language, but it is very different from PHP, in the go statement, the string value cannot be changed once it is set.
Example:
VaR s string = "hello"
S [0] = 'C'
This operation is not allowed. In addition, string-type data must be cited Using Sequence instead of simple sequence, because simple arguments represent a character rather than a string, you can use reverse arguments for strings, that is the inverse example we used when reading the MySQL statement, for example, select * From 'user' where...
If I want to modify the string, how can I modify it? Let's take a look at the Token Generation of the variable:
To implement this in go, the following method is required:
S: = "hello" // returns the value of seconds. The type is string C: = [] Rune (s) // convert the string s into a numeric data group. Rune is the alias C [0] = 'C' of int32. // modify the value of the first element in the Data Group S2: = string (c) // convert the numeric Variant C into a string and reload the value to S2. printf ("% s \ n", S2) // outputs
It is a little tricky, at least more troublesome than PHP.
S: = "this is" + "String concatenation" s: = 'actually, this can be the same, but there will be an additional line character.
In addition to the Notes mentioned above, some reserved words in go cannot be used, as shown below:
Break default func interface select
Case defer go map struct
Chan else goto package Switch
Const fallthrough if range type
For Import Return var continue
This article finds that there are not many types of go, but their functions are not weak, because go can customize them, here I will mention that there will be clear remarks in later articles. in addition, the Go variable or constant method is more active than the variable method. There are many variable methods. When defining constants, pay attention to a variable type, pay attention to the special type of the string when setting the variable volume. This is all the points.
I hope that my friends can leave an article out, http://see7di.cnblogs.com is grateful here!
I have set up a QQ group. If you are interested in commenting on the go statement, you can join: 195112