Home > Backend Development > Golang > What are the differences between golang and python?

What are the differences between golang and python?

coldplay.xixi
Release: 2020-06-24 13:20:13
Original
3146 people have browsed it

What are the differences between golang and python?

The differences between golang and python are:

Mainly in terms of syntax.

1.golang is very readable, and corresponds to &&, ||. This also makes golang look more like a traditional programming language, rather than python's or, and.

2. It is difficult to modify the string, just rearrange it if necessary.

3. Strings often need to be converted back and forth between string and []byte. strconv must be used to convert numbers to strings.

4.if, else, elif must be on the same line as the matching {.

5. Use custom structs all the time, both to initialize the structure and to convert json into a data structure. If the json is converted into a composite structure, you need to nest the struct, which is very

Many times strcut is used as map in python.

6. Define type test struct. If you want to get an array of test, use []*test instead of []test.

7. The first letter of the struct and the elements inside it must be capitalized, otherwise it may not be accessible.

8. Golang’s map is much more difficult to use than python. There is no dict.keys() or dict.values(). If you want to convert the map into other structures, you can only traverse the map.

9. Declaration and assignment use:=.

10. There are no sets or tuples, so use slices frequently.

11. If there is no __getattr, check whether it exists frequently.

12. All the referenced packages and declared variables must be used, otherwise the compilation will not pass.

13. Arrays do not have flexible usages such as [:-1], [::-1], a,b,c=[1,2,3].

14. If you can determine the type returned by the function, do not use interface{}. Even if the structure is complex, use strcut to return it. If interface{} is returned, then basic usages such as

string() and for traversal cannot be used.

15. The null pointer is nil. None in python is replaced by nil in golang. Often write err != nil to determine whether there is an error.

Recommended tutorial: "go language tutorial"

The above is the detailed content of What are the differences between golang and python?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template