Extract a named field in Julia - getfield() Method

Last Updated : 12 Jul, 2025
The getfield() is an inbuilt function in julia which is used to extract a named field from the specified value of composite type.
Syntax: getfield(value, name::Symbol) Parameters:
  • value: Specified value of composite type.
  • name::Symbol: Specified symbol.
Returns: It returns the extracted named field from the specified value of composite type.
Example 1: Python
# Julia program to illustrate 
# the use of getfield() method
 
# Getting the extracted named field
# from the specified value of composite type. 
a = 5//2
println(getfield(a, :num))
Output:
5
Example 2: Python
# Julia program to illustrate 
# the use of getfield() method
 
# Getting the extracted named field
# from the specified value of composite type. 
a = 7//3
println(getfield(a, :num))
Output:
7
Comment