مثال مشغلي عضوية بيثون Python Membership Operators Example#

مثال مشغلي عضوية بيثون

 Python Membership Operators Example#


مثال مشغلي عضوية بيثون Python Membership Operators Example#

يختبر مشغلو عضوية Python العضوية في تسلسل ، مثل السلاسل أو القوائم أو المجموعات.  هناك اثنين من مشغلي العضوية كما هو موضح أدناه -
المشغلالوصفمثال
inيتم التقييم إلى صواب إذا وجد متغيرًا في التسلسل المحدد وخطأًا على خلاف ذلك.
x in y, here in results in a 1 if x is a member of sequence y.
not inيتم التقييم إلى صواب إذا لم يجد متغير في التسلسل المحدد وخطأ في غير ذلك.x not in y, here not in results in a 1 if x is not a member of sequence y.

مثال Example

#!/usr/bin/python

a = 10
b = 20
list = [1, 2, 3, 4, 5 ];

if ( a in list ):
   print "Line 1 - a is available in the given list"
else:
   print "Line 1 - a is not available in the given list"

if ( b not in list ):
   print "Line 2 - b is not available in the given list"
else:
   print "Line 2 - b is available in the given list"

a = 2
if ( a in list ):
   print "Line 3 - a is available in the given list"
else:
   print "Line 3 - a is not available in the given list"
عند تنفيذ البرنامج أعلاه فإنه ينتج
 النتيجة التالية -

Line 1 - a is not available in the given list
Line 2 - b is not available in the given list
Line 3 - a is available in the given list


المشاركات الشائعة من هذه المدونة

Software Development Life Cycle دورة حياة تطوير البرمجيات او النظام

نموذج الشلال بالتفصيل دورة حياة تطوير النظام او البرمجيات SDLC Waterfall Model#