Go笔记-01-类型系统与结构化编程

绪论

学习目标:高高手

为什么冯诺依曼体系架构经久不衰:解耦的思想

在这里插入图片描述

Go语言体系

在这里插入图片描述

初识Go

Go语言特性

在这里插入图片描述

环境准备

在这里插入图片描述

Go类型系统

类型体系

在这里插入图片描述

Hello Word常见的十种写法:

在这里插入图片描述

package main

import (
	"fmt"
	"time"
)

type HelloWorld struct {
	value string
}
type ShowHello interface {
	Print1()
}

func (hw HelloWorld) Print1() {
	fmt.Println(hw.value)
}

func BiBao() {
	var str = "hello world!"
	f := func() {
		fmt.Println(str)
	}
	f()
}

func TestChan(ch <-chan string) {
	for v := range ch {
		fmt.Print(v)
	}
}

func main() {
	fmt.Println("第一种:直接常量")
	fmt.Println("hello world!")

	fmt.Println("第二种:格式化常量")
	fmt.Printf("%s\n", "hello world!")

	fmt.Println("第三种:直接变量")
	var str = "hello world!"
	fmt.Println(str)

	fmt.Println("第四种:数字转义")
	fmt.Printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n", 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!')
	fmt.Printf("%c%c%c%c%c%c%c%c%c%c%c%c\n", 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33)

	fmt.Println("第五种:切片实现")
	var slice = make([]string, 0)
	slice = append(slice, "hello")
	slice = append(slice, " ")
	slice = append(slice, "world")
	slice = append(slice, "!")
	var str2 string
	for _, s := range slice {
		str2 += s
	}
	fmt.Println(str2)

	fmt.Println("第六种:map实现")
	var m1 = map[int]string{
		1: "hello",
		2: "world!",
	}
	fmt.Printf("%s %s\n", m1[1], m1[2])
	fmt.Println("第七种:结构体实现")
	hw := HelloWorld{value: "hello world!"}
	fmt.Println(hw.value)

	fmt.Println("第八种:接口实现")
	var sh ShowHello = hw
	sh.Print1()

	fmt.Println("第九种:闭包实现")
	BiBao()

	fmt.Println("第十种:channel实现")
	var ch = make(chan string, 8)
	go TestChan(ch)
	ch <- "hello "
	ch <- "world!"
	time.Sleep(time.Second * 3)

}

C:\Users\henry.shaw\AppData\Local\JetBrains\GoLand2023.3\tmp\GoLand\___go_build_helloword_go.exe
第一种:直接常量
hello world!                                 
第二种:格式化常量                           
hello world!                                 
第三种:直接变量                             
hello world!                                 
第四种:数字转义                             
104,101,108,108,111,32,119,111,114,108,100,33
hello world!                                 
第五种:切片实现                             
hello world!
第六种:map实现
hello world!
第七种:结构体实现
hello world!
第八种:接口实现
hello world!
第九种:闭包实现
hello world!
第十种:channel实现
hello world!
Process finished with the exit code 0

数据类型

在这里插入图片描述

常量

在这里插入图片描述

变量

在这里插入图片描述

数值型运算

在这里插入图片描述
在这里插入图片描述

浮点数比较

在这里插入图片描述

Go结构化编程

编程核心:数据结构+算法

在这里插入图片描述

顺序结构

在这里插入图片描述

选择结构

在这里插入图片描述

循环结构

在这里插入图片描述

goto语句

在这里插入图片描述

函数

在这里插入图片描述

错误处理

在这里插入图片描述

总结

关键字

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值