Bir struct Tanımlama
Alanları tek bir türde bir araya getirin.
Bir struct Tanımlama, CoddyKit'te ücretsiz bir Mojo Academy dersidir. Bu, 4 dersinin 1. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Mojo Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Mojo Academy kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
Why You Need a struct
When values belong together, like a point's x and y, you can bundle them into one custom type. In Mojo that bundle is a struct. 📦
The struct Keyword
You define a new type with the struct keyword, a name, and a colon. Everything indented under it belongs to that type.
struct Point:
passNaming Your Type
Struct names use CapitalizedNames by convention, so Point or BankAccount. This makes your types easy to spot in code.
struct BankAccount:
passFields Hold the Data
Inside a struct you list its fields, the named pieces of data it stores. Each field is declared with var and a type.
struct Point:
var x: Int
var y: IntEvery Field Needs a Type
Mojo structs are static, so each field must state its type up front. That lets the compiler lay out memory efficiently.
var name: String
var age: IntA struct Is a Blueprint
A struct definition is just a blueprint. It describes the shape of data but does not create any actual value on its own yet.
Instances Are the Real Thing
From one blueprint you make many instances, each with its own values. The struct is the mold; instances are what comes out of it.
Grouping Beats Loose Variables
Without a struct you juggle separate x and y variables everywhere. A struct keeps related data together, so it travels as one unit.
Structs Are Value Types
In Mojo a struct is a value type. Assigning it copies the data, which keeps behavior predictable and fast by default.
A Complete Mini Struct
Here is a full struct with two fields. This single definition now describes every Point your program will ever create.
struct Point:
var x: Int
var y: IntRead It Top to Bottom
Read a struct as: here is a new type, and here is the data it carries. That mental model carries you through the whole course.
Quick Check
Let us check your grasp of defining a struct.
Recap
You met the struct: a blueprint that bundles typed fields into one value type. Next you will fill it with real data using __init__. 🎉
Sıkça Sorulan Sorular
“Bir struct Tanımlama” dersi ücretsiz mi?
Evet — “Bir struct Tanımlama” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Mojo Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Mojo Academy kursu toplamda 4 dersten oluşur.
“Bir struct Tanımlama” dersinde ne öğreneceğim?
Alanları tek bir türde bir araya getirin. Mojo Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Mojo Academy öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Mojo Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 1. dersidir.
“Bir struct Tanımlama” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Mojo Academy dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Mojo Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- Bir struct Tanımlama
- Alanlar ve __init__ Metodu
- Bir struct'a Metot Ekleme
- Struct'lar ve Python Sınıfları