কম্পিউটার টিউটোরিয়াল

পাইথন মেম্বারশিপ অপারেটর (Python Membership Operators)


ভূমিকা

পাইথনের মেম্বারশিপ অপারেটরগুলো কোনো সিকোয়েন্স (স্ট্রিং, লিস্ট, টাপল ইত্যাদি) এর মধ্যে একটি ভেরিয়েবল বা মান রয়েছে কিনা তা পরীক্ষা করে।

মেম্বারশিপ অপারেটর টেবিল

ক্রমঅপারেটর ও বিবরণউদাহরণ
১ in
যদি ভেরিয়েবল সিকোয়েন্সে পাওয়া যায় তবে True, অন্যথায় False।
x in y → x যদি y-র সদস্য হয় তবে ১ (True)
২ not in
যদি ভেরিয়েবল সিকোয়েন্সে না পাওয়া যায় তবে True, অন্যথায় False।
x not in y → x যদি y-র সদস্য না হয় তবে ১ (True)

উদাহরণ প্রোগ্রাম

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

if a in my_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 my_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 my_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
  1. পাইথন অপারেটর প্রসিডেন্স (Python Operators Precedence)

  2. পাইথন বিটওয়াইজ অপারেটর (Python Bitwise Operators)

  3. পাইথন কমপ্যারিজন অপারেটর (Python Comparison Operators)

  4. পাইথন আритমেটিক অপারেটর (Python Arithmetic Operators)