تتناول المقابلة العديد من المواضيع المثيرة للاهتمام حول تطور بايثون وأسباب إنشاء اللغة ورؤية Guido لمستقبلها.
يتناول المحتوى بعض النقاط الرئيسية مثل:
1. تاريخ وخلفية لغة بايثون وما أدى إلى إنشائها.
2. تفاصيل حول بعض التصميمات والمفاهيم الرئيسية في بايثون مثل التحويل الديناميكي والجمل المشروطة والمفاهيم الأساسية الأخرى.
3. أهداف وفلسفة تصميم بايثون وأهمية القراءة السهلة والكتابة البسيطة والكود القابل للفهم.
4. المزايا والتحديات في تطوير لغة برمجة مفتوحة المصدر وكيف تم تطوير وتوسيع مجتمع بايثون.
5. الدور الحالي والمستقبلي لبايثون في مجالات مثل تطوير الويب والذكاء الاصطناعي والعلوم والبيانات.
إنها مقابلة شيقة وتعطي نظرة جيدة على تاريخ وفلسفة بايثون. أتمنى أن يكون المقطع قد قدم لك معلومات قيمة حول لغة بايثون ورؤية مبتكرها.
يتناول المحتوى بعض النقاط الرئيسية مثل:
1. تاريخ وخلفية لغة بايثون وما أدى إلى إنشائها.
2. تفاصيل حول بعض التصميمات والمفاهيم الرئيسية في بايثون مثل التحويل الديناميكي والجمل المشروطة والمفاهيم الأساسية الأخرى.
3. أهداف وفلسفة تصميم بايثون وأهمية القراءة السهلة والكتابة البسيطة والكود القابل للفهم.
4. المزايا والتحديات في تطوير لغة برمجة مفتوحة المصدر وكيف تم تطوير وتوسيع مجتمع بايثون.
5. الدور الحالي والمستقبلي لبايثون في مجالات مثل تطوير الويب والذكاء الاصطناعي والعلوم والبيانات.
إنها مقابلة شيقة وتعطي نظرة جيدة على تاريخ وفلسفة بايثون. أتمنى أن يكون المقطع قد قدم لك معلومات قيمة حول لغة بايثون ورؤية مبتكرها.
👍1
Forwarded from Python Pro | برو بايثون
مرحبا بكم في قناة برو بايثون! نحن نبحث عن أفكار جديدة لتحسين القناة ونود سماع رأيكم. ما الذي تودون رؤيته أكثر في القناة؟
Anonymous Poll
15%
أخبار وتحديثات حول اللغة بايثون
15%
توجيهات ونصائح حول كيفية بناء مشاريع بايثون
8%
مقابلات مع مبرمجين محترفين في بايثون
15%
مراجعات لأفضل الكتب والدورات التعليمية للغة بايثون
8%
تحديات برمجية أسبوعية
38%
دروس متقدمة في البرمجة بلغة بايثون
👍2
البرمجة غير المتزامنة (Asynchronous programming) هي نمط من أنماط البرمجة يتيح للتطبيقات التعامل مع العديد من الأشياء في نفس الوقت. في البرمجة المتزامنة، يمكن للتطبيقات تنفيذ العديد من الأشياء في نفس الوقت، وهو ما يجعلها مثالية للأنشطة مثل الويب أو القراءة من قاعدة البيانات أو الكتابة فيها، أو أي نشاط آخر يتطلب الانتظار لاستكمال العمليات.
في Python، يمكننا استخدام الوحدة النمطية asyncio لكتابة البرامج غير المتزامنة. تمت إضافة asyncio في Python 3.4 كجزء من مكتبة القياسية، وتم تحسينها في الإصدارات اللاحقة.
ألق نظرة على الكود التالي:
في الكود أعلاه، نحن نستخدم الكلمة الرئيسية async لتعريف الدالة كدالة غير متزامنة. ثم نستخدم الكلمة الرئيسية await لتعليق تنفيذ الدالة حتى يتم استكمال العملية الأخرى (في هذه الحالة، asyncio.sleep(1)).
الآن، دعنا ننظر إلى مثال أكثر تعقيدا:
في هذا الكود، لدينا دالة say_after تأخذ وقت الانتظار والرسالة كمعلمات، وتطبع الرسالة بعد الانتظار للوقت المحدد. في الدالة main، نحن ننتظر الانتهاء من say_after قبل الانتقال إلى الخطوة التالية. هذا يعني أن الرسائل ستتم طباعتها بالترتيب، وليس في نفس الوقت، حتى مع استخدام البرمجة غير المتزامنة.
لكن، إذا كنا نريد تنفيذ العديد من الأشياء في نفس الوقت، يمكننا استخدام asyncio.gather. هذا ينفذ الوظائف غير المتزامنة في نفس الوقت، ولا ينتظر الانتهاء من واحدة قبل البدء في الأخرى.
في هذا الكود، نحن نستخدم asyncio.create_task لإنشاء مهمتين غير متزامنتين، ثم ننتظر الانتهاء من كلتا المهمتين باستخدام await. هذا يعني أن الرسائل ستتم طباعتها في نفس الوقت، وليس بالترتيب.
في Python، يمكننا استخدام الوحدة النمطية asyncio لكتابة البرامج غير المتزامنة. تمت إضافة asyncio في Python 3.4 كجزء من مكتبة القياسية، وتم تحسينها في الإصدارات اللاحقة.
ألق نظرة على الكود التالي:
python
import asyncio
async def main():
print('Hello ...')
await asyncio.sleep(1)
print('... World!')
# Python 3.7+
asyncio.run(main())
في الكود أعلاه، نحن نستخدم الكلمة الرئيسية async لتعريف الدالة كدالة غير متزامنة. ثم نستخدم الكلمة الرئيسية await لتعليق تنفيذ الدالة حتى يتم استكمال العملية الأخرى (في هذه الحالة، asyncio.sleep(1)).
الآن، دعنا ننظر إلى مثال أكثر تعقيدا:
python
import asyncio
import time
async def say_after(delay, what):
await asyncio.sleep(delay)
print(what)
async def main():
print(f"started at {time.strftime('%X')}")
await say_after(1, 'hello')
await say_after(2, 'world')
print(f"finished at {time.strftime('%X')}")
# Python 3.7+
asyncio.run(main())
في هذا الكود، لدينا دالة say_after تأخذ وقت الانتظار والرسالة كمعلمات، وتطبع الرسالة بعد الانتظار للوقت المحدد. في الدالة main، نحن ننتظر الانتهاء من say_after قبل الانتقال إلى الخطوة التالية. هذا يعني أن الرسائل ستتم طباعتها بالترتيب، وليس في نفس الوقت، حتى مع استخدام البرمجة غير المتزامنة.
لكن، إذا كنا نريد تنفيذ العديد من الأشياء في نفس الوقت، يمكننا استخدام asyncio.gather. هذا ينفذ الوظائف غير المتزامنة في نفس الوقت، ولا ينتظر الانتهاء من واحدة قبل البدء في الأخرى.
python
import asyncio
import time
async def say_after(delay, what):
await asyncio.sleep(delay)
print(what)
async def main():
task1 = asyncio.create_task(
say_after(1, 'hello'))
task2 = asyncio.create_task(
say_after(2, 'world'))
print(f"started at {time.strftime('%X')}")
# Wait until both tasks are completed (should take
# around 2 seconds.)
await task1
await task2
print(f"finished at {time.strftime('%X')}")
# Python 3.7+
asyncio.run(main())
في هذا الكود، نحن نستخدم asyncio.create_task لإنشاء مهمتين غير متزامنتين، ثم ننتظر الانتهاء من كلتا المهمتين باستخدام await. هذا يعني أن الرسائل ستتم طباعتها في نفس الوقت، وليس بالترتيب.
👍1
الـ Multithreading والـ Multitasking هما نمطان من أنماط البرمجة تستخدمان لتنفيذ العديد من الأشياء في نفس الوقت.
Multـالithreading يعني تشغيل العديد من الخيوط (threads) في نفس الوقت.ل ك خيط يعمل على مهمة معينة، ويمكن للخيوط أن تتشارك في الذاكرة والموارد الأخرى.
الـ Multitasking يعني تشغيل العديد من المهام (tasks) في نفس الوقت. المهذ ههام يمكن أن تكون عمليات (processes) أو خيوط (threads)، ولكن في كلتا الحالتين، يتم تنفيذها في نفس الوقت.
فالر بقين الـ Multithreading والـ Multitasking يكمن في كيفية تنفيذ الأشياء في نفس الوقت. في الـ Multithreading، يتم تنفيذ الخيوط في نفس العملية، ويمكن تاهقاسم الذاكرة والموارد الأخرى. في الـ Multitasking، يمكن أن تكون المهام عمليات مستقلة، وليس لديها وصول مباشر إلى الذاكرة أو الموارد الأخرى للمهام الأخرى.
الـ asyncio في Python هو نمط آخر من البرمجة يتيح تنفيذ العديد من الأشياء في نفس الوقت. ومع ذلك، بدلاً من استخدام العديد من الخيوط أو العمليات، يستخدم asyncio ما يسمى بالـ coroutines، والتي تتيح لك تعليق واستئناف الوظائف في أي وقت، مما يتيح تنفيذ العديد من الأشياء في نفس الوقت دو النحاجة إلى الخيوط أو العمليات.
إليك مثالاً على كيفية استخدام الـ Multithreading في Python:
في هذا المثال، لدينا خيطين: واحد لطباعة الأرقام من 0 إلى 9، والآخر لطباعة الحروف من 'a' إلى 'j'. نستخدم الدالة start لبدء كل خيط، والتي تبدأ بتنفيذ الوظيفة المستهدفة في خيط جديد.
وهنا كيف يمكننا القيام بنفس الشيء باستخدام asyncio:
في هذا المثال، لدينا نفس الوظائف كما في المثال السابق، ولكننا نستخدم الكلمة الرئيسية async لتعريفها كـ coroutines، ونستخدم الكلمة الرئيسية await لتعليق تنفيذ الـ coroutine حتى يتم استكمال العملية الأخرى (في هذه الحالة، asyncio.sleep(1)). نستخدم asyncio.gather لتنفيذ الـ coroutines في نفس الوقت، ونستخدم loop.run_until_complete لتشغيل الـ event loop حتى يتم استكمال كل الـ coroutines.
Multـالithreading يعني تشغيل العديد من الخيوط (threads) في نفس الوقت.ل ك خيط يعمل على مهمة معينة، ويمكن للخيوط أن تتشارك في الذاكرة والموارد الأخرى.
الـ Multitasking يعني تشغيل العديد من المهام (tasks) في نفس الوقت. المهذ ههام يمكن أن تكون عمليات (processes) أو خيوط (threads)، ولكن في كلتا الحالتين، يتم تنفيذها في نفس الوقت.
فالر بقين الـ Multithreading والـ Multitasking يكمن في كيفية تنفيذ الأشياء في نفس الوقت. في الـ Multithreading، يتم تنفيذ الخيوط في نفس العملية، ويمكن تاهقاسم الذاكرة والموارد الأخرى. في الـ Multitasking، يمكن أن تكون المهام عمليات مستقلة، وليس لديها وصول مباشر إلى الذاكرة أو الموارد الأخرى للمهام الأخرى.
الـ asyncio في Python هو نمط آخر من البرمجة يتيح تنفيذ العديد من الأشياء في نفس الوقت. ومع ذلك، بدلاً من استخدام العديد من الخيوط أو العمليات، يستخدم asyncio ما يسمى بالـ coroutines، والتي تتيح لك تعليق واستئناف الوظائف في أي وقت، مما يتيح تنفيذ العديد من الأشياء في نفس الوقت دو النحاجة إلى الخيوط أو العمليات.
إليك مثالاً على كيفية استخدام الـ Multithreading في Python:
python
import threading
def print_numbers():
for i in range(10):
print(i)
def print_letters():
for letter in 'abcdefghij':
print(letter)
t1 = threading.Thread(target=print_numbers)
t2 = threading.Thread(target=print_letters)
t1.start()
t2.start()
في هذا المثال، لدينا خيطين: واحد لطباعة الأرقام من 0 إلى 9، والآخر لطباعة الحروف من 'a' إلى 'j'. نستخدم الدالة start لبدء كل خيط، والتي تبدأ بتنفيذ الوظيفة المستهدفة في خيط جديد.
وهنا كيف يمكننا القيام بنفس الشيء باستخدام asyncio:
python
import asyncio
async def print_numbers():
for i in range(10):
print(i)
await asyncio.sleep(1)
async def print_letters():
for letter in 'abcdefghij':
print(letter)
await asyncio.sleep(1)
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(print_numbers(), print_letters()))
loop.close()
في هذا المثال، لدينا نفس الوظائف كما في المثال السابق، ولكننا نستخدم الكلمة الرئيسية async لتعريفها كـ coroutines، ونستخدم الكلمة الرئيسية await لتعليق تنفيذ الـ coroutine حتى يتم استكمال العملية الأخرى (في هذه الحالة، asyncio.sleep(1)). نستخدم asyncio.gather لتنفيذ الـ coroutines في نفس الوقت، ونستخدم loop.run_until_complete لتشغيل الـ event loop حتى يتم استكمال كل الـ coroutines.
👍1
Multithreading and multitasking are two programming patterns used to execute multiple tasks concurrently.
Multithreading refers to running multiple threads simultaneously. Each thread works on a specific task, and threads can share memory and other resources.
Multitasking, on the other hand, refers to running multiple tasks concurrently. The tasks can be processes or threads, but in both cases, they are executed simultaneously.
The difference between multithreading and multitasking lies in how things are executed concurrently. In multithreading, threads are executed within the same process and can share memory and other resources. In multitasking, tasks can be independent processes that don't have direct access to each other's memory or resources.
Asyncio in Python is another programming pattern that enables concurrent execution of multiple tasks. However, instead of using multiple threads or processes, asyncio utilizes what are called coroutines, which allow you to suspend and resume functions at any point, enabling the execution of multiple tasks concurrently without the need for threads or processes.
Here's an example of using multithreading in Python:
In this example, we have two threads: one for printing numbers from 0 to 9 and another for printing letters from 'a' to 'j'. We use the
And here's how we can achieve the same using asyncio:
In this example, we have the same functions as before, but we define them as coroutines using the
Multithreading refers to running multiple threads simultaneously. Each thread works on a specific task, and threads can share memory and other resources.
Multitasking, on the other hand, refers to running multiple tasks concurrently. The tasks can be processes or threads, but in both cases, they are executed simultaneously.
The difference between multithreading and multitasking lies in how things are executed concurrently. In multithreading, threads are executed within the same process and can share memory and other resources. In multitasking, tasks can be independent processes that don't have direct access to each other's memory or resources.
Asyncio in Python is another programming pattern that enables concurrent execution of multiple tasks. However, instead of using multiple threads or processes, asyncio utilizes what are called coroutines, which allow you to suspend and resume functions at any point, enabling the execution of multiple tasks concurrently without the need for threads or processes.
Here's an example of using multithreading in Python:
python
import threading
def print_numbers():
for i in range(10):
print(i)
def print_letters():
for letter in 'abcdefghij':
print(letter)
t1 = threading.Thread(target=print_numbers)
t2 = threading.Thread(target=print_letters)
t1.start()
t2.start()
In this example, we have two threads: one for printing numbers from 0 to 9 and another for printing letters from 'a' to 'j'. We use the
start function to start each thread, which begins executing the targeted function in a new thread.And here's how we can achieve the same using asyncio:
python
import asyncio
async def print_numbers():
for i in range(10):
print(i)
await asyncio.sleep(1)
async def print_letters():
for letter in 'abcdefghij':
print(letter)
await asyncio.sleep(1)
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(print_numbers(), print_letters()))
loop.close()
In this example, we have the same functions as before, but we define them as coroutines using the
async keyword. We use the await keyword to suspend the execution of the coroutine until the other operation (in this case, asyncio.sleep(1)) is completed. We use asyncio.gather to execute the coroutines concurrently, and we use loop.run_until_complete to run the event loop until all coroutines are completed.مراجعة بعض الأساسيات في لغة Python:
1. المتغيرات والنصوص:
في Python، يمكنك تعريف المتغيرات وتخزين القيم فيها. على سبيل المثال:
2. الطباعة:
يمكنك استخدام الدالة
3. الشرطية:
يمكنك استخدام الشروط لاتخاذ قرارات مستندة إلى قيم معينة. على سبيل المثال:
4. الحلقات:
يمكنك استخدام الحلقات لتكرار تنفيذ قطعة من الكود. في Python، هناك حلقتان رئيسيتان:
5. القوائم (اللوائح):
تعتبر القوائم هيكل بيانات يسمح بتخزين مجموعة من العناصر. يمكنك الوصول إلى العناصر بواسطة مؤشرات (فهرسة) أو باستخدام حلقات. على سبيل المثال:
python
numbers = [1, 2, 3, 4, 5]
print(numbers[0]) # الوصول إلى العنصر الأول في القائمة
print(len(numbers)) # الحصول على عدد العناصر في القائمة
for number in numbers:
print(number)
1. المتغيرات والنصوص:
في Python، يمكنك تعريف المتغيرات وتخزين القيم فيها. على سبيل المثال:
python
name = "John" # تعريف متغير يحمل اسم
age = 25 # تعريف متغير يحمل عمر
2. الطباعة:
يمكنك استخدام الدالة
print() لطباعة النصوص أو القيم على الشاشة. على سبيل المثال:python
print("مرحبًا بك في Python!")
3. الشرطية:
يمكنك استخدام الشروط لاتخاذ قرارات مستندة إلى قيم معينة. على سبيل المثال:
python
age = 18
if age >= 18:
print("أنت بالفعل بالغ!")
else:
print("أنت قاصر!")
4. الحلقات:
يمكنك استخدام الحلقات لتكرار تنفيذ قطعة من الكود. في Python، هناك حلقتان رئيسيتان:
for و while. على سبيل المثال:python
for i in range(1, 6):
print(i)
i = 1
while i <= 5:
print(i)
i += 1
5. القوائم (اللوائح):
تعتبر القوائم هيكل بيانات يسمح بتخزين مجموعة من العناصر. يمكنك الوصول إلى العناصر بواسطة مؤشرات (فهرسة) أو باستخدام حلقات. على سبيل المثال:
python
numbers = [1, 2, 3, 4, 5]
print(numbers[0]) # الوصول إلى العنصر الأول في القائمة
print(len(numbers)) # الحصول على عدد العناصر في القائمة
for number in numbers:
print(number)
Review of basics in the Python language:
1. Variables and Strings:
In Python, you can define variables and store values in them. For example:
2. Printing:
You can use the
3. Conditionals:
You can use conditionals to make decisions based on certain values. For example:
4. Loops:
You can use loops to repeatedly execute a piece of code. In Python, there are two main types of loops:
5. Lists:
Lists are a data structure that allows you to store a collection of items. You can access items by indices or using loops. For example:
python
numbers = [1, 2, 3, 4, 5]
print(numbers[0]) # accessing the first item in the list
print(len(numbers)) # getting the number of items in the list
for number in numbers:
print(number)
1. Variables and Strings:
In Python, you can define variables and store values in them. For example:
python
name = "John" # defining a variable to hold a name
age = 25 # defining a variable to hold an age
2. Printing:
You can use the
print() function to print text or values to the screen. For example:python
print("Welcome to Python!")
3. Conditionals:
You can use conditionals to make decisions based on certain values. For example:
python
age = 18
if age >= 18:
print("You are already an adult!")
else:
print("You are a minor!")
4. Loops:
You can use loops to repeatedly execute a piece of code. In Python, there are two main types of loops:
for and while. For example:python
for i in range(1, 6):
print(i)
i = 1
while i <= 5:
print(i)
i += 1
5. Lists:
Lists are a data structure that allows you to store a collection of items. You can access items by indices or using loops. For example:
python
numbers = [1, 2, 3, 4, 5]
print(numbers[0]) # accessing the first item in the list
print(len(numbers)) # getting the number of items in the list
for number in numbers:
print(number)
قوة لغة Python في التعامل مع القوائم (Lists) يمكن رؤيتها بوضوح في عملية الـ Slicing. الـ Slicing يتيح لك استخراج جزء من القائمة بناءً على الفهرسة (Indices)، وهو عمل مهم ومنتشر في برمجة Python. دعنا نلقي نظرة على كيفية استخدام الـ Slicing في Python مع بعض الأمثلة التوضيحية:
للبدء، دعنا ننشئ قائمة ببضع عناصر:
1. استخراج جزء محدد من القائمة:
يمكنك استخدام الـ Slicing لاستخراج جزء معين من القائمة باستخدام الفهرسة. على سبيل المثال، إذا أردنا استخراج العناصر من الفهرس 2 إلى 5، يمكننا كتابة:
2. استخراج جزء بخطوة محددة:
يمكنك أيضًا تحديد خطوة (Step) للـ Slicing، حيث يتم استخراج العناصر بفاصل زمني محدد. على سبيل المثال، إذا أردنا استخراج العناصر بفاصل زمني 2، يمكننا كتابة:
3. استخراج جزء من القائمة من النهاية:
يمكنك أيضًا استخراج جزء من القائمة من النهاية باستخدام الفهرسة السالبة. على سبيل المثال، إذا أردنا استخراج آخر 3 عناصر، يمكننا كتابة:
4. عكس القائمة:
باستخدام الفهرسة السالبة، يمكنك أيضًا عكس القائم
ة بسهولة. على سبيل المثال:
هذه بعض الأمثلة التوضيحية لاستخدام الـ Slicing في Python. يمكنك استخدام هذه الطرق لاستخراج الجزء المناسب من القائمة وتطبيقها في مختلف سيناريوهات البرمجة التي تحتاجها. تذكر أن الفهرسة في Python تبدأ من 0، وأن الـ Slicing يستخدم نهايات مفتوحة (Exclusive)، مما يعني أن العنصر الأخير في الـ Slicing ليس مشمولًا في النتيجة.
للبدء، دعنا ننشئ قائمة ببضع عناصر:
python
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
1. استخراج جزء محدد من القائمة:
يمكنك استخدام الـ Slicing لاستخراج جزء معين من القائمة باستخدام الفهرسة. على سبيل المثال، إذا أردنا استخراج العناصر من الفهرس 2 إلى 5، يمكننا كتابة:
python
slice1 = numbers[2:6]
print(slice1) # الناتج: [3, 4, 5, 6]
2. استخراج جزء بخطوة محددة:
يمكنك أيضًا تحديد خطوة (Step) للـ Slicing، حيث يتم استخراج العناصر بفاصل زمني محدد. على سبيل المثال، إذا أردنا استخراج العناصر بفاصل زمني 2، يمكننا كتابة:
python
slice2 = numbers[1:8:2]
print(slice2) # الناتج: [2, 4, 6, 8]
3. استخراج جزء من القائمة من النهاية:
يمكنك أيضًا استخراج جزء من القائمة من النهاية باستخدام الفهرسة السالبة. على سبيل المثال، إذا أردنا استخراج آخر 3 عناصر، يمكننا كتابة:
python
slice3 = numbers[-3:]
print(slice3) # الناتج: [8, 9, 10]
4. عكس القائمة:
باستخدام الفهرسة السالبة، يمكنك أيضًا عكس القائم
ة بسهولة. على سبيل المثال:
python
reversed_list = numbers[::-1]
print(reversed_list) # الناتج: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
هذه بعض الأمثلة التوضيحية لاستخدام الـ Slicing في Python. يمكنك استخدام هذه الطرق لاستخراج الجزء المناسب من القائمة وتطبيقها في مختلف سيناريوهات البرمجة التي تحتاجها. تذكر أن الفهرسة في Python تبدأ من 0، وأن الـ Slicing يستخدم نهايات مفتوحة (Exclusive)، مما يعني أن العنصر الأخير في الـ Slicing ليس مشمولًا في النتيجة.
Python slicing is a powerful feature that allows you to extract a portion of a list based on indexing. It is a widely used and important concept in Python programming. Let's take a detailed look at how to use slicing in Python with some illustrative examples:
To start, let's create a list with some elements:
1. Extracting a specific portion of the list:
You can use slicing to extract a specific portion of the list using indexing. For example, if we want to extract the elements from index 2 to 5, we can write:
2. Extracting a portion with a specified step:
You can also specify a step value for slicing, which extracts elements at a specified interval. For example, if we want to extract elements with a step of 2, we can write:
3. Extracting a portion from the end of the list:
You can also extract a portion of the list from the end using negative indexing. For example, if we want to extract the last 3 elements, we can write:
4. Reversing the list:
Using negative indexing, you can easily reverse the list. For example:
These are some illustrative examples of using slicing in Python. You can use these techniques to extract the desired portion of a list and apply them in various programming scenarios. Remember that indexing in Python starts from 0, and slicing uses exclusive end-points, meaning the last element in the slice is not included in the result.
To start, let's create a list with some elements:
python
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
1. Extracting a specific portion of the list:
You can use slicing to extract a specific portion of the list using indexing. For example, if we want to extract the elements from index 2 to 5, we can write:
python
slice1 = numbers[2:6]
print(slice1) # Output: [3, 4, 5, 6]
2. Extracting a portion with a specified step:
You can also specify a step value for slicing, which extracts elements at a specified interval. For example, if we want to extract elements with a step of 2, we can write:
python
slice2 = numbers[1:8:2]
print(slice2) # Output: [2, 4, 6, 8]
3. Extracting a portion from the end of the list:
You can also extract a portion of the list from the end using negative indexing. For example, if we want to extract the last 3 elements, we can write:
python
slice3 = numbers[-3:]
print(slice3) # Output: [8, 9, 10]
4. Reversing the list:
Using negative indexing, you can easily reverse the list. For example:
python
reversed_list = numbers[::-1]
print(reversed_list) # Output: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
These are some illustrative examples of using slicing in Python. You can use these techniques to extract the desired portion of a list and apply them in various programming scenarios. Remember that indexing in Python starts from 0, and slicing uses exclusive end-points, meaning the last element in the slice is not included in the result.
📣 انضم إلى قناة "برو فلاتر" للاحتراف في تطوير التطبيقات! 🚀
هل تبحث عن الاحترافية والتميز في تطوير تطبيقات فلاتر؟ إذاً، فإن قناة "برو فلاتر" هي المكان المثالي لك! 📲💡
ما يميز قناتنا؟ 🌟
✅ محتوى متميز وحصري يغطي جميع جوانب تطوير تطبيقات فلاتر.
✅ نصائح وإرشادات قيمة من خبراء متمرسين في مجال تطوير تطبيقات فلاتر.
✅ مشاركة تقنيات مبتكرة وأفكار جديدة لتعزيز قدراتك في تطوير التطبيقات.
✅ فرص التواصل والتفاعل مع مجتمع من المطورين المحترفين والمهتمين بتطوير تطبيقات فلاتر.
انضم إلينا عبر الرابط التالي:
https://t.me/flutterpro23
سنقدم لك كل ما تحتاجه للارتقاء بمهاراتك في تطوير تطبيقات فلاتر. انضم إلى قناتنا الآن واستفد من المحتوى المميز والتواصل مع مجتمع المطورين المتميزين.
انشر الكلمة وشارك الرابط مع الأصدقاء والزملاء الذين يهتمون بتطوير تطبيقات فلاتر. معًا، سنصل إلى مستوى جديد من الاحترافية في عالم تطوير التطبيقات!
#بروفلاتر #تطوير_التطبيقات #فلاتر #احترافية
هل تبحث عن الاحترافية والتميز في تطوير تطبيقات فلاتر؟ إذاً، فإن قناة "برو فلاتر" هي المكان المثالي لك! 📲💡
ما يميز قناتنا؟ 🌟
✅ محتوى متميز وحصري يغطي جميع جوانب تطوير تطبيقات فلاتر.
✅ نصائح وإرشادات قيمة من خبراء متمرسين في مجال تطوير تطبيقات فلاتر.
✅ مشاركة تقنيات مبتكرة وأفكار جديدة لتعزيز قدراتك في تطوير التطبيقات.
✅ فرص التواصل والتفاعل مع مجتمع من المطورين المحترفين والمهتمين بتطوير تطبيقات فلاتر.
انضم إلينا عبر الرابط التالي:
https://t.me/flutterpro23
سنقدم لك كل ما تحتاجه للارتقاء بمهاراتك في تطوير تطبيقات فلاتر. انضم إلى قناتنا الآن واستفد من المحتوى المميز والتواصل مع مجتمع المطورين المتميزين.
انشر الكلمة وشارك الرابط مع الأصدقاء والزملاء الذين يهتمون بتطوير تطبيقات فلاتر. معًا، سنصل إلى مستوى جديد من الاحترافية في عالم تطوير التطبيقات!
#بروفلاتر #تطوير_التطبيقات #فلاتر #احترافية
Telegram
برو فلاتر | Flutter Pro
Your ultimate destination for acquiring knowledge and skills in advanced Flutter app development
___<<>>___
المصدر الأمثل لاكتساب المعرفة والمهارات في تطوير تطبيقات Flutter المتقدمة.
___<<>>___
المصدر الأمثل لاكتساب المعرفة والمهارات في تطوير تطبيقات Flutter المتقدمة.