Why I am not to update String as value in Dictionary if Dictionary is created with Int64 values

When you initialize your dict like the above, the Dict created becomes specific for string keys and int values:

julia> d = Dict("a"=>1, "b" => 2, "c" => 3)
Dict{String, Int64} with 3 entries:
  "c" => 3
  "b" => 2
  "a" => 1

(note the Dict{String, Int64}).

If you want the Dict to contain more general values than those used to initialize the dict, you can be explicit about that, for example:

julia> d = Dict{String,Union{String,Int}}("a"=>1, "b" => 2, "c" => 3)
Dict{String, Union{Int64, String}} with 3 entries:
  "c" => 3
  "b" => 2
  "a" => 1

julia> d["c"] = "a"
"a"

julia> d
Dict{String, Union{Int64, String}} with 3 entries:
  "c" => "a"
  "b" => 2
  "a" => 1

or, even more general:

julia> d = Dict{String,Any}("a"=>1, "b" => 2, "c" => 3)
Dict{String, Any} with 3 entries:
  "c" => 3
  "b" => 2
  "a" => 1

julia> d["c"] = [1,2,3]
3-element Vector{Int64}:
 1
 2
 3

julia> d
Dict{String, Any} with 3 entries:
  "c" => [1, 2, 3]
  "b" => 2
  "a" => 1
6 Likes