# Julia equivalent to Python's id function

**URL:** https://discourse.julialang.org/t/julia-equivalent-to-pythons-id-function/86136
**Category:** New to Julia
**Created:** [August 22, 2022, 1:52pm UTC](https://discourse.julialang.org/t/julia-equivalent-to-pythons-id-function/86136 "2022-08-22T13:52:14Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Frankiewaang](https://avatars.discourse-cdn.com/v4/letter/f/f9ae1b/32.png) [@Frankiewaang](https://discourse.julialang.org/u/Frankiewaang)
#### Post date: [August 22, 2022, 1:52pm UTC](https://discourse.julialang.org/t/julia-equivalent-to-pythons-id-function/86136/1 "2022-08-22T13:52:14Z")

</div>

Hi, guys  
Is there a Julia build-in function existed that has the same functionality as python’s `id` function?

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/f/8fdceb668b08486a3a9bb95bb517c5e943403cea.png)

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [August 22, 2022, 2:17pm UTC](https://discourse.julialang.org/t/julia-equivalent-to-pythons-id-function/86136/2 "2022-08-22T14:17:52Z")

</div>

Depending on what you want to use this for, you might find the function `hash` useful

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [August 22, 2022, 2:38pm UTC](https://discourse.julialang.org/t/julia-equivalent-to-pythons-id-function/86136/3 "2022-08-22T14:38:10Z")

</div>

I guess the closest would be `pointer_from_objref`. But it is very rare that you need to use this.

---

<div class="post-metadata">

### Author: ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)
#### Post date: [August 22, 2022, 2:58pm UTC](https://discourse.julialang.org/t/julia-equivalent-to-pythons-id-function/86136/4 "2022-08-22T14:58:08Z")

</div>

There’s `Base.objectid`:

```julia
help?> Base.objectid
  objectid(x) -> UInt

  Get a hash value for x based on object identity. objectid(x)==objectid(y) if x === y.

  See also hash, IdDict.

```

`IdDict` uses `objectid` to check for equality, and its docs have an example to illustrate the difference between value equality and object equality:

```julia

  julia> Dict(true => "yes", 1 => "no", 1.0 => "maybe")
  Dict{Real, String} with 1 entry:
    1.0 => "maybe"
  
  julia> IdDict(true => "yes", 1 => "no", 1.0 => "maybe")
  IdDict{Any, String} with 3 entries:
    true => "yes"
    1.0 => "maybe"
    1 => "no"

```

> The Dict keys are all `isequal` and therefore get hashed the same, so they get overwritten. The IdDict hashes by object-id, and thus preserves the 3 different keys.
