{"id":55,"date":"2026-03-01T15:18:33","date_gmt":"2026-03-01T10:18:33","guid":{"rendered":"https:\/\/gigz.pk\/python\/?post_type=lesson&#038;p=55"},"modified":"2026-03-13T09:25:42","modified_gmt":"2026-03-13T04:25:43","slug":"membership-and-identity-operators","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/python\/lesson\/membership-and-identity-operators\/","title":{"rendered":"Membership and Identity Operators"},"content":{"rendered":"\n<p>Membership and identity operators are used to test specific conditions in Python programs. While membership operators check whether a value exists inside a sequence, identity operators check whether two variables refer to the same object in memory.<\/p>\n\n\n\n<p>Understanding these operators helps in writing efficient and logical programs.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>MEMBERSHIP OPERATORS<\/strong><\/h1>\n\n\n\n<p>Membership operators are used to check whether a value is present in a sequence such as a string, list, or tuple.<\/p>\n\n\n\n<p>There are two membership operators:<\/p>\n\n\n\n<p>in<br>not in<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>IN OPERATOR<\/strong><\/h1>\n\n\n\n<p>The in operator returns True if the specified value exists in the sequence.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<p>numbers = [1, 2, 3, 4, 5]<br>print(3 in numbers)<\/p>\n\n\n\n<p>Output will be True.<\/p>\n\n\n\n<p>Example with string:<\/p>\n\n\n\n<p>text = &#8220;Python Programming&#8221;<br>print(&#8220;Python&#8221; in text)<\/p>\n\n\n\n<p>Output will be True.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>NOT IN OPERATOR<\/strong><\/h1>\n\n\n\n<p>The not in operator returns True if the specified value does not exist in the sequence.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<p>numbers = [1, 2, 3, 4, 5]<br>print(10 not in numbers)<\/p>\n\n\n\n<p>Output will be True.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>IDENTITY OPERATORS<\/strong><\/h1>\n\n\n\n<p>Identity operators are used to compare the memory location of two objects. They check whether two variables refer to the same object.<\/p>\n\n\n\n<p>There are two identity operators:<\/p>\n\n\n\n<p>is<br>is not<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>IS OPERATOR<\/strong><\/h1>\n\n\n\n<p>The is operator returns True if both variables refer to the same object in memory.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<p>x = [1, 2, 3]<br>y = x<\/p>\n\n\n\n<p>print(x is y)<\/p>\n\n\n\n<p>Output will be True because both variables point to the same object.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>IS NOT OPERATOR<\/strong><\/h1>\n\n\n\n<p>The is not operator returns True if two variables do not refer to the same object.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<p>x = [1, 2, 3]<br>y = [1, 2, 3]<\/p>\n\n\n\n<p>print(x is not y)<\/p>\n\n\n\n<p>Output will be True because both lists are separate objects in memory.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>DIFFERENCE BETWEEN EQUALITY AND IDENTITY<\/strong><\/h1>\n\n\n\n<p>The equality operator == checks whether the values are equal.<br>The identity operator is checks whether the objects are the same in memory.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<p>x = [1, 2, 3]<br>y = [1, 2, 3]<\/p>\n\n\n\n<p>print(x == y)<br>Output will be True<\/p>\n\n\n\n<p>print(x is y)<br>Output will be False<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>WHY THESE OPERATORS ARE IMPORTANT<\/strong><\/h1>\n\n\n\n<p>Membership operators help in searching and validating data inside sequences. Identity operators help in understanding how objects are stored in memory.<\/p>\n\n\n\n<p>Mastering membership and identity operators allows you to write more efficient and logically correct Python programs.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/python\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">PYTHON FUNDAMENTALS (PYF) > Operators > Membership and Identity Operators<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1773375980757\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n","protected":false},"menu_order":15,"template":"","class_list":["post-55","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Membership and Identity Operators - One Language. Endless Possibilities<\/title>\n<meta name=\"description\" content=\"Learn Python membership and identity operators (in, not in, is, is not) to check sequences and compare objects in memory.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/python\/lesson\/membership-and-identity-operators\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Membership and Identity Operators - One Language. Endless Possibilities\" \/>\n<meta property=\"og:description\" content=\"Learn Python membership and identity operators (in, not in, is, is not) to check sequences and compare objects in memory.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/python\/lesson\/membership-and-identity-operators\/\" \/>\n<meta property=\"og:site_name\" content=\"One Language. Endless Possibilities\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-13T04:25:43+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/membership-and-identity-operators\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/membership-and-identity-operators\\\/\",\"name\":\"Membership and Identity Operators - One Language. Endless Possibilities\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\"},\"datePublished\":\"2026-03-01T10:18:33+00:00\",\"dateModified\":\"2026-03-13T04:25:43+00:00\",\"description\":\"Learn Python membership and identity operators (in, not in, is, is not) to check sequences and compare objects in memory.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/membership-and-identity-operators\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/membership-and-identity-operators\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/membership-and-identity-operators\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PYTHON FUNDAMENTALS (PYF) > Operators > Membership and Identity Operators\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\",\"name\":\"One Language. Endless Possibilities\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/python\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Membership and Identity Operators - One Language. Endless Possibilities","description":"Learn Python membership and identity operators (in, not in, is, is not) to check sequences and compare objects in memory.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/python\/lesson\/membership-and-identity-operators\/","og_locale":"en_US","og_type":"article","og_title":"Membership and Identity Operators - One Language. Endless Possibilities","og_description":"Learn Python membership and identity operators (in, not in, is, is not) to check sequences and compare objects in memory.","og_url":"https:\/\/gigz.pk\/python\/lesson\/membership-and-identity-operators\/","og_site_name":"One Language. Endless Possibilities","article_modified_time":"2026-03-13T04:25:43+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/python\/lesson\/membership-and-identity-operators\/","url":"https:\/\/gigz.pk\/python\/lesson\/membership-and-identity-operators\/","name":"Membership and Identity Operators - One Language. Endless Possibilities","isPartOf":{"@id":"https:\/\/gigz.pk\/python\/#website"},"datePublished":"2026-03-01T10:18:33+00:00","dateModified":"2026-03-13T04:25:43+00:00","description":"Learn Python membership and identity operators (in, not in, is, is not) to check sequences and compare objects in memory.","breadcrumb":{"@id":"https:\/\/gigz.pk\/python\/lesson\/membership-and-identity-operators\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/python\/lesson\/membership-and-identity-operators\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/python\/lesson\/membership-and-identity-operators\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/python\/"},{"@type":"ListItem","position":2,"name":"PYTHON FUNDAMENTALS (PYF) > Operators > Membership and Identity Operators"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/python\/#website","url":"https:\/\/gigz.pk\/python\/","name":"One Language. Endless Possibilities","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/python\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson\/55","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/media?parent=55"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}