تنبيه النظام

الرجاء تحديد نص من المقال أولاً لإنشاء بطاقة المشاركة.

1 / 10
Ahmed Bouchefra Profile Header
A.B

;Ahmed Bouchefra

1.2k منشورات
100k قارئ
9 كاتب

أنا أحمد بوشفرة، مبرمج ومؤلف تقني (Tech Author) متخصص في تبسيط مفاهيم البرمجة وتطوير الويب. منذ عام 2017، أقدّم محتوى موجّهًا للمبرمجين عبر موقع 10xdev blog، بالإضافة إلى منصّات مثل SitePoint وSmashing Magazine. أسلوبي عملي ويساعد المبرمجين على فهم التقنيات بسرعة وبناء مهارات قوية بثقة. كما تعاونت مع دار النشر Packt في إصدار كتاب Full Stack Development with Angular and GraphQL، مما يعكس جودة المحتوى الذي أقدمه للمبرمجين. يحتوي هذا الموقع على مقالات كتبتها للجمهور العربي، بالإضافة إلى مقالاتي المترجمة من موقع 10xdev blog ومقالات أخرى ساهم بها مبرمجون من مختلف الأنحاء.

Python 3.7 Data Classes — Tutorial by Example

جاهز

ملخص سريع للمقال باستخدام الذكاء الاصطناعي

إذا لم يكن لديك الوقت لقراءة المقال بالكامل، اضغط على زر نسخ لنسخ التوجيه (Prompt) أدناه، ثم اضغط على زر فتح ChatGPT للصقه هناك والحصول على أهم النقاط.

لخص هذا المقال واستخرج أهم النقاط (Key Takeaways) مع شرح المصطلحات التقنية. العنوان: Python 3.7 Data Classes — Tutorial by Example - الرابط:
https://www.ahmedbouchefra.com/python-data-classes-tutorial-by-example/

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')