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

**URL:** <https://discourse.julialang.org/t/why-i-am-not-to-update-string-as-value-in-dictionary-if-dictionary-is-created-with-int64-values/102952>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 18, 2023, 12:47pm UTC](https://discourse.julialang.org/t/why-i-am-not-to-update-string-as-value-in-dictionary-if-dictionary-is-created-with-int64-values/102952 "2023-08-18T12:47:57Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [August 18, 2023, 12:52pm UTC](https://discourse.julialang.org/t/why-i-am-not-to-update-string-as-value-in-dictionary-if-dictionary-is-created-with-int64-values/102952/2 "2023-08-18T12:52:40Z")

</div>

> [@saampandit](#):
>
> `d = Dict("a"=>1, "b" => 2, "c" => 3)`

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

```julia
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
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
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

```

---

_[View the full topic](https://discourse.julialang.org/t/why-i-am-not-to-update-string-as-value-in-dictionary-if-dictionary-is-created-with-int64-values/102952)._
