Structs

इंटरमीडिएट Julia

Anthony Markham

Quantitative Developer

Structs - परिचय

  • Structs, composite types का उपयोग हैं.
  • ये अन्य types जैसे ही हैं, बस इनमें जितने चाहें fields हो सकते हैं.
  • हम composite type से एक object बना सकते हैं, जो हमारे type का प्रतिनिधित्व होता है.
इंटरमीडिएट Julia

Structs - सिंटैक्स

  • कोई structure परिभाषित करने के लिए struct कीवर्ड का उपयोग करें.
  • struct के अंदर हर field को struct घोषणा के भीतर indented रखें.
struct Person
    age
    height
    location
end
steve = Person(18, 180, "London")
println(steve.height)
180
इंटरमीडिएट Julia

Structs - ऑब्जेक्ट का typeof

  • steve का type Person है.
struct Person
    age
    height
    location
end
steve = Person(18, 180, "London")
println(typeof(steve))
Person
इंटरमीडिएट Julia

Structs - immutability दिखाना

  • कोई struct डिफ़ॉल्ट रूप से immutable होता है.
# It's Steve's birthday!
steve = Person(18, 180, "London")
steve.age = 19
setfield!: immutable struct of type Person cannot be changed
इंटरमीडिएट Julia

Structs - mutable structs

  • mutable struct बनाने के लिए mutable कीवर्ड का उपयोग करें.
mutable struct Person
    age
    height
    location
end
steve = Person(18, 180, "London")
steve.age = 19
println(steve)
Person(19, 180, "London")
इंटरमीडिएट Julia

Structs - typed structs

  • हम अपने struct परिभाषा में हर field के लिए data type निर्दिष्ट कर सकते हैं.
mutable struct Person
    age::Int64
    height::Int64
    location::String
end
steve = Person(18.5, 180, "London")
InexactError: Int64(18.5)
इंटरमीडिएट Julia

अभ्यास करते हैं!

इंटरमीडिएट Julia

Preparing Video For Download...