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)

💡 உதவிக்குறிப்பு:

in செயலி பட்டியல்கள், டப்பிள்கள், செட்கள், அகராதிகள் மற்றும் சரங்கள் போன்ற தரவு கட்டமைப்புகளில் மதிப்புகளைத் தேட பயனுள்ளதாக இருக்கும். இது குறிப்பாக ஒரு குறிப்பிட்ட உருப்படி ஒரு கலவையில் இருக்கிறதா இல்லையா என்பதை சோதிக்க விரும்பும் போது பயனுள்ளதாக இருக்கும்.

Exercise

What does the in operator do?

in செயலி என்ன செய்கிறது?

in செயலி என்ன செய்கிறது?

Checks if a value exists in a sequence
✓ சரி! in செயலி ஒரு மதிப்பு ஒரு தொடர்வரிசையில் (பட்டியல், சரம், டப்பிள் போன்றவை) இருக்கிறதா என சோதிக்கிறது
Adds a value to a list
✗ தவறு! பட்டியலில் மதிப்பைச் சேர்க்க append() அல்லது insert() முறைகள் பயன்படுத்தப்படுகின்றன
Compares two values
✗ தவறு! இரண்டு மதிப்புகளை ஒப்பிட comparison operators (==, !=, >, < போன்றவை) பயன்படுத்தப்படுகின்றன