Python Membership Operators

পাইথন সদস্য ফাংশন

Python Membership Operators

Membership Operators

Membership operators are used to test if a sequence is presented in an object:

সদস্য অপারেটরগুলি একটি বস্তুতে একটি অ্যারে প্রদান করা হয়েছে কিনা তা পরীক্ষা করতে ব্যবহৃত হয়:

Membership Operators Reference

Operator Description Example
in Returns True if a sequence with the specified value is present in the object x in y
not in Returns True if a sequence with the specified value is not present in the object x not in y

Examples

ExampleGet your own Python Server

Check if "banana" is present in a list:

fruits = ["apple", "banana", "cherry"]

print("banana" in fruits)

Example

Check if "pineapple" is NOT present in a list:

fruits = ["apple", "banana", "cherry"]

print("pineapple" not in fruits)

Membership in Strings

The membership operators also work with strings:

সদস্য অপারেটররাও স্ট্রিংগুলির সাথে কাজ করে:

Example

text = "Hello World"

print("H" in text)
print("hello" in text)
print("z" not in text)

💡টিপ:

ইন ফাংশন ডেটা স্ট্রাকচার যেমন তালিকা, টিপল, সেট, অভিধান এবং স্ট্রিংগুলিতে মান অনুসন্ধানের জন্য দরকারী। এটি বিশেষভাবে কার্যকর যখন আপনি পরীক্ষা করতে চান যে একটি নির্দিষ্ট আইটেম একটি মিশ্রণে উপস্থিত আছে কি না।

Exercise

What does the in operator do?

প্রক্রিয়াধীন কি করে?

প্রক্রিয়াধীন কি করে?

Checks if a value exists in a sequence
✓ ঠিক আছে! ইন ফাংশন পরীক্ষা করে যে একটি মান একটি অ্যারেতে আছে কিনা (তালিকা, স্ট্রিং, ডবল, ইত্যাদি)।
Adds a value to a list
✗ ভুল! তালিকায় একটি মান যোগ করতে append() বা insert() পদ্ধতি ব্যবহার করা হয়
Compares two values
✗ ভুল! তুলনা অপারেটর (==, !=, >, < ইত্যাদি) দুটি মান তুলনা করতে ব্যবহৃত হয়