julia> [i for i in (1,2,3)]
3-element Array{Int64,1}:
1
2
3
julia> (i for i in (1,2,3))
Base.Generator{Tuple{Int64,Int64,Int64},getfield(Main, Symbol("##5#6"))}(getfield(Main, Symbol("##5#6"))(), (1, 2, 3))
julia> methods(Tuple)
# 5 methods for generic function "(::Type)":
[1] (::Type{T})(x::Tuple) where T<:Tuple in Base at tuple.jl:229
[2] (::Type{Tuple})(nt::NamedTuple{names,T} where T<:Tuple) where names in Base at namedtuple.jl:116
[3] (::Type{T})(nt::NamedTuple) where T<:Tuple in Base at namedtuple.jl:122
[4] (::Type{Tuple})(index::CartesianIndex) in Base.IteratorsMD at multidimensional.jl:95
[5] (::Type{T})(itr) where T<:Tuple in Base at tuple.jl:243
这个语法和 Python 很像,Python 中 [i for i in (1, 2, 3)] 叫列表推导式(list comprehension),返回一个 list。
而 (i for i in (1, 2, 3)) 叫生成器表达式(generator expression),返回一个 generator。