小编VC *_*aly的帖子

在Go中使用int和str的数组

我正在尝试在Go中使用数组,但找不到在同一数组中可用于整数和字符串的任何东西。我正在寻找一些有助于解决此问题的文档。

我有它在Python中工作,我正在尝试将其翻译成Go。我在网上找到的大多数信息都显示整数数组或字符串数​​组,但未同时显示两者。

整数和字符串将被传递到另一个函数中,具体取决于整数的值,确定将哪个字符串连接到数组的字符串值。

这是来自Python的示例:

# This is the set arrays
List = [[1, "Pie"], [10, "Fish"], [5, "apples"]]

#This is the code of the function that each array will be passed into
 if list[0] == 1:
        return "There is one " + list[1] + "."
    else:
        return "There are " + str(list[0]) + " " + list[1] + "."
Run Code Online (Sandbox Code Playgroud)

最终打印输出:

# This is the set arrays
List = [[1, "Pie"], [10, "Fish"], [5, "apples"]]

#This is the code of the …
Run Code Online (Sandbox Code Playgroud)

tuples go

1
推荐指数
1
解决办法
63
查看次数

标签 统计

go ×1

tuples ×1