تنبيه

الرجاء تحديد نص من المقال أولاً.

محتوى محمي

لتحميل هذا المقال، يرجى تفعيل جرس الإشعارات أو اختيار طريقة اشتراك أخرى.

Ahmed Bouchefra

الرئيسية
Ahmed Bouchefra

أحمد بوشفرة

Software Engineer & Tech Author

ابدأ هنا
ابدأ هنا
المكتبة
المكتبة
أكاديمية بايثون
أكاديمية بايثون
تطبيق اختبارات البرمجة
تطبيق اختبارات البرمجة
دورات يوديمي
دورات يوديمي
المسارات
المسارات
الملخصات
الملخصات
الأدوات
الأدوات
اشترك
اشترك
كتب فريق 10xdevblog
كتب فريق 10xdevblog
الكاتب: أحمد بوشفرة

Python 3.7 Data Classes — Tutorial by Example

اضغط على زر PDF لتحميل المقال كملف للقراءة لاحقاً

ملاحظة: هذا المقال بقلم أحمد بوشفرة. الآراء الواردة تعبر عن الكاتب.

أحمد بوشفرة: مبرمج ومؤلف تقني، أساعد المطورين على بناء تطبيقات ويب حديثة وسريعة.

يمكنك التواصل مع الكاتب لطلب خدمات برمجية عبر:

يمكنك أيضاً نشر مقالك هنا والترويج لخدماتك أمام جمهور من المبرمجين. تواصل معنا

لخص هذا المقال باستخدام ChatGPT

انسخ الأمر أدناه والصقه في ChatGPT للحصول على ملخص سريع للمقال:

لخص لي هذا المقال في نقاط رئيسية: https://www.ahmedbouchefra.com/python-data-classes-tutorial-by-example/ تم النسخ!
فتح ChatGPT

Data classes are a new feature of Python 3.7 that allows you to create classes that contain only fields of data and methods to get or access the fields. They serve as containers for data that can be used by other classes that implement the logic of your application.

First of all, you need to have the latest Python 3.7 version installed on your system. From your terminal, type the following command to start an interactive Python shell:

$ python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information. 

Next you can use data classes by importing the dataclass decorator from the dataclasses module. For instance, this is a simple example:

from dataclasses import dataclass

@dataclass
class Contact:
    name: str
    email: str
    phone: str

You created a Contact type with the name, email and phone fields of type str.

You can now instances of Contact:

>>> contact = Contact("test","[email protected]","00 00 00 00")
>>> contact
Contact(name='test', email='[email protected]', phone='00 00 00 00')

You need to provide the positional arguments: ‘name’, ‘email’, and ‘phone’ or otherwise you’ll get an error. You can also use keyword arguments:

>>> contact1 = Contact(name="test1",email="[email protected]",phone="+01 00 00 00")
>>> contact1
Contact(name='test1', email='[email protected]', phone='+01 00 00 00')

هل لديك سؤال أو استفسار؟ اترك تعليقاً بالأسفل:

احصل على المحتوى الجديد فور نشره ⚡

اختر الطريقة الأنسب لك لمتابعتنا والحصول على التحديثات مجاناً.
(اضغط على رابط التفعيل الذي سيصلك لفتح المحتوى)

عرض كل بدائل الاشتراك

احصل على موارد مجانية! 📚

اشترك في القائمة البريدية واحصل على كتب ومصادر تعليمية مجانية

تنبيه هام:

للاشتراك بنجاح، يرجى فتح الصفحة في متصفح خارجي (مثل Chrome أو Safari) وليس متصفح التطبيق المدمج.

📚 المكتبة المجانية

حمّل كتب وأدلة PDF مجانية في البرمجة وتطوير الويب

تصفح المكتبة

شارك المقال

Python 3.7 Data Classes — Tutorial by Example
0:00 / 0:00