我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

从头开始编程语言

In python you can use the following syntax as a shortcut:

a[-1]    # last item in the array
a[-2:]   # last two items in the array
a[:-2]   # everything except the last two items

Does Go have shortcuts similar to the second and third example when creating new slices?

Nope, you have to use len(a).

a[len(a)-1]
a[len(a)-2:]
a[:len(a)-2]

近期文章

  • 为什么我的Go程序无法删除文件?
  • 我们是否应该在lang列表中使用struct指针?
  • 如何用Go语言在另一个函数中调用一个函数?
  • 通过Golang exec运行FFMPEG命令
  • 如何在Golang中发送硬编码的复杂json响应
  • 当测试文件在模块中时,如何运行“去测试”?
  • 在golang中将子字符串转换为int
  • golang包的模拟方法
  • golang,陶醉,如何解析发布json?
  • 在GO中将嵌套的JSON转换为csv
  • 使用扫描程序每行多个令牌的更好方法?
  • 将参数传递给Go IIFE(以下javascript示例)
  • Golang中的RESTful服务是否应包含客户端界面?
  • golang-用于上传大文件的功能
  • OpenGL中的错误绘图模型
  • go中的结构和使用指针
  • 如何从一个bytes.Buffer读取多次?
  • golang并发同步问题
  • Golang:select语句在不应该退出时退出
  • 转到:使用multiWriter将作家添加到io.writer

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华