{"id":33529,"date":"2020-03-17T13:57:47","date_gmt":"2020-03-17T08:27:47","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=33529"},"modified":"2020-03-17T13:57:47","modified_gmt":"2020-03-17T08:27:47","slug":"walrus-operator-in-python-3-8","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/walrus-operator-in-python-3-8\/","title":{"rendered":"Walrus Operator in Python 3.8"},"content":{"rendered":"<p>Python 3.8 remains in development. But many alpha versions are released. one among the newest features in Python 3.8 is that the Walrus Operator. during this article, we\u2019re getting to discuss the Walrus operator and explain it with an example.<\/p>\n<p><strong>Introduction<\/strong><\/p>\n<p>Walrus-operator is another name for assignment expressions. consistent with the official documentation, it\u2019s how to assign to variables within an expression using the notation NAME := expr. The Assignment expressions allow a worth to be assigned to a variable, even a variable that doesn\u2019t exist yet, within the context of expression instead of as a stand-alone statement.<\/p>\n<h3 id=\"code\"><strong>Code :<\/strong><\/h3>\n[pastacode lang=\u201dpython\u201d manual=\u201da%20%3D%20%5B1%2C%202%2C%203%2C%204%5D%20%0Aif%20(n%20%3A%3D%20len(a))%20%3E%203%3A%20%0A%20%20%20%20print(f%22List%20is%20too%20long%20(%7Bn%7D%20elements%2C%20expected%20%3C%3D%203)%22)%20\u2033 message=\u201d\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<h3 id=\"output\"><strong>OUTPUT:<\/strong><\/h3>\n[pastacode lang=\u201dpython\u201d manual=\u201dList%20is%20too%20long%20(4%20elements%2C%20expected%20%3C%3D3)\u201d message=\u201d\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p><strong>Example \u2013<\/strong><\/p>\n<p>Let\u2019s plan to understand Assignment Expressions more clearly with the help of an example using both Python 3.7 and Python 3.8. Here we\u2019ve a listing of dictionaries is named \u201csample_data\u201d, which contains the user Id, name and a Boolean called is completed.<\/p>\n[pastacode lang=\u201dpython\u201d manual=\u201dsample_data%20%3D%20%5B%20%0A%20%20%20%20%7B%22userId%22%3A%201%2C%20%20%22name%22%3A%20%22rahul%22%2C%20%22completed%22%3A%20False%7D%2C%20%0A%20%20%20%20%7B%22userId%22%3A%201%2C%20%22name%22%3A%20%22rohit%22%2C%20%22completed%22%3A%20False%7D%2C%20%0A%20%20%20%20%7B%22userId%22%3A%201%2C%20%20%22name%22%3A%20%22ram%22%2C%20%22completed%22%3A%20False%7D%2C%20%0A%20%20%20%20%7B%22userId%22%3A%201%2C%20%20%22name%22%3A%20%22ravan%22%2C%20%22completed%22%3A%20True%7D%20%0A%5D%20%0A%20%20%0Aprint(%22With%20Python%203.8%20Walrus%20Operator%3A%22)%20%20%0Afor%20entry%20in%20sample_data%3A%20%20%0A%20%20%20%20if%20name%20%3A%3D%20entry.get(%22name%22)%3A%20%0A%20%20%20%20%20%20%20%20print(f\u2019Found%20name%3A%20%22%7Bname%7D%22\u2032)%20%0A%20%20%0Aprint(%22Without%20Walrus%20operator%3A%22)%20%0Afor%20entry%20in%20sample_data%3A%20%0A%20%20%20%20name%20%3D%20entry.get(%22name%22)%20%0A%20%20%20%20if%20name%3A%20%0A%20%20%20%20%20%20%20%20print(f\u2019Found%20name%3A%20%22%7Bname%7D%22\u2032)%20\u2033 message=\u201d\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<h3 id=\"output-2\"><strong>OUTPUT:<\/strong><\/h3>\n[pastacode lang=\u201dpython\u201d manual=\u201dWith%20python%203.8%20walrus%20operators%20%3A%0AFound%20name%3A%20%E2%80%9Crahul%E2%80%9D%0AFound%20name%3A%20%E2%80%9Crohit%E2%80%9D%0AFound%20name%3A%20%E2%80%9Cram%E2%80%9D%0AFound%20name%3A%20%E2%80%9Cravan%E2%80%9D%0A%0AWithout%20Walrus%20operators%20%3A%0AFound%20name%3A%20%E2%80%9Crahul%E2%80%9D%0AFound%20name%3A%20%E2%80%9Crohit%E2%80%9D%0AFound%20name%3A%20%E2%80%9Cram%E2%80%9D%0AFound%20name%3A%20%E2%80%9Cravan%E2%80%9D%0A%E2%80%83%0A\u201d message=\u201d\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python 3.8 remains in development. But many alpha versions are released. one among the newest features in Python 3.8 is that the Walrus Operator. during this article, we\u2019re getting to discuss the Walrus operator and explain it with an example. Introduction Walrus-operator is another name for assignment expressions. consistent with the official documentation, it\u2019s how [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":33606,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[86908,86909,86907],"class_list":["post-33529","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding","tag-operators-expression-in-python","tag-operators-in-python-walrus","tag-walrus-operators"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/33529","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=33529"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/33529\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media\/33606"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=33529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=33529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=33529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}