{"id":5344,"date":"2020-02-03T23:27:26","date_gmt":"2020-02-03T17:57:26","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=5344"},"modified":"2020-02-03T23:27:35","modified_gmt":"2020-02-03T17:57:35","slug":"the-walrus-operator-in-python-3-8","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/the-walrus-operator-in-python-3-8\/","title":{"rendered":"THE WALRUS OPERATOR IN PYTHON 3.8"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">THE WALRUS OPERATOR IN PYTHON 3.8<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Date: 29\/01\/2020<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Introduction<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Walrus Operator is another name for Assignment Expressions. I will explain in detail in this article.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Assignment Expressions are written with a new notation which is colon followed by equal to expression ( <strong>:= <\/strong>) . It  allows you to assign a value to a variable and check conditions  for that variable in the same expression. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For Example, Lets find out the given number is odd or even   <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">if((number:=27)%2==0):\n   print(\"Given number is even\")\nelse:\n   print(\"Given number is odd\")<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the Output :<br><br><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"157\" height=\"26\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/01\/Screenshot-from-2020-01-31-11-57-48-3.png\" alt=\"\" class=\"wp-image-5388\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/01\/Screenshot-from-2020-01-31-11-57-48-3.png 157w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/01\/Screenshot-from-2020-01-31-11-57-48-3-150x26.png 150w\" sizes=\"(max-width: 157px) 100vw, 157px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Advantages of using the assignment  expressions is  we can directly assign a value to the variable and checks for the condition is satisfied or not at the same time.<br><br>Whereas in previous python versions , we have to  assign a value for a variable separately and checks the condition by using that variable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For Example , In python 3.7 <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">number=27\nif(number%2==0):\n   print(\"Given number is even\")\nelse:\n   print(\"Given number is odd\")<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Walrus Operator reduces the code lines and making things easier<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Conclusion<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Thank You for using <a href=\"https:\/\/pheonixsolutions.com\/\">pheonixsolutions<\/a>. <br>If you like the blog share it with your friends and others also.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>THE WALRUS OPERATOR IN PYTHON 3.8 Date: 29\/01\/2020 Introduction Walrus Operator is another name for Assignment Expressions. I will explain [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[292,745],"class_list":["post-5344","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-python","tag-walrus-operator","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-1oc","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5344","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=5344"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5344\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=5344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=5344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=5344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}