Skip to content
Related Articles
Open in App
Not now

Related Articles

Getting type of keys and values of a Dictionary in Julia – keytype() and valtype() Methods

Improve Article
Save Article
Like Article
  • Last Updated : 17 Jun, 2021
Improve Article
Save Article
Like Article

The keytype() is an inbuilt function in julia which is used to return the key type of the specified array.
 

Syntax: 
keytype(A::AbstractArray) 
or 
keytype(T::Type{<:AbstractArray})
Parameters: 
 

  • A::AbstractArray: Specified array.
  • T::Type{<:AbstractArray}: Specified dictionary type.

Returns: It returns the key type of the specified array. 
 

Example: 
 

Python




# Julia program to illustrate
# the use of keytype() method
 
# Getting the key type of the specified array.
println(keytype([5, 10, 15]))
println(keytype([2 4; 6 8]))
println(keytype(Dict(Int32(1) => "GFG")))
println(keytype(Dict(Int8(1) => "gfg")))

Output: 
 

 

valtype()

The valtype() is an inbuilt function in julia which is used to return the value type of the specified array.
 

Syntax: 
valtype(A::AbstractArray) 
or 
valtype(T::Type{<:AbstractArray})
Parameters: 
 

  • A::AbstractArray: Specified array.
  • T::Type{<:AbstractArray}: Specified dictionary type.

Returns: It returns the value type of the specified array. 
 

Example: 
 

Python




# Julia program to illustrate
# the use of valtype() method
 
# Getting the value type of the specified array.
println(valtype(["Geeks", "GFG", "gfg"]))
println(valtype([1, 2, 3]))
println(valtype(Dict(Int32(1) => "GFG")))
println(valtype(Dict(Int8(1) => 23)))

Output: 
 

 


My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!