{"id":7752,"date":"2024-02-24T21:12:53","date_gmt":"2024-02-24T15:42:53","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=7752"},"modified":"2024-02-24T21:12:55","modified_gmt":"2024-02-24T15:42:55","slug":"python-variables-and-operators","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/python-variables-and-operators\/","title":{"rendered":"Python &#8211; Variables and Operators"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong><em>Variables<\/em><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">  Python does not have a particular syntax or command for creating or declaring variable. A variable is created at the moment we assign a value to it. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ex: x=4<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">   Here variable &#8216;x&#8217; is assigned with value 4 and is considered integer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">x=&#8221;John&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">  Here variable x is assigned string value. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So, we dont have separate syntax for declaring a variable. The moment we assign a value, the variable is declared with the type of value we assigned.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>Conditions to name the variable:<\/em><\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Must contain numbers, letters, or underscores<\/li>\n\n\n\n<li>Should not start with the number<\/li>\n\n\n\n<li>Spaces are not allowed<\/li>\n\n\n\n<li>Cannot be keywords of Python like print, break, etc.\u2026<\/li>\n\n\n\n<li>Case sensitive<\/li>\n\n\n\n<li>Short and descriptive are best.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>Operators:<\/em><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> We can perform arithmetic operations using arithmetic operators.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ex: print(10+5)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> Here addition will be done, and we will get output as 15.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/02\/addition.png\"><img fetchpriority=\"high\" decoding=\"async\" width=\"502\" height=\"620\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/02\/addition.png\" alt=\"\" class=\"wp-image-7757\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/02\/addition.png 502w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/02\/addition-243x300.png 243w\" sizes=\"(max-width: 502px) 100vw, 502px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The same way we can use  other operators like logical,assignement and comparision operators.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>Conditional Operators:<\/em><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> To execute statements based on conditions, we use this. The conditional operators are <strong>&#8220;if&#8221;,&#8221;if-else&#8221;<\/strong>,etc..<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Some condition based executions are:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/02\/operators1.png\"><img decoding=\"async\" width=\"672\" height=\"896\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/02\/operators1.png\" alt=\"\" class=\"wp-image-7756\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/02\/operators1.png 672w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/02\/operators1-225x300.png 225w\" sizes=\"(max-width: 672px) 100vw, 672px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Just introduced how variables and operators are used in Python language.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Variables Python does not have a particular syntax or command for creating or declaring variable. A variable is created at [&hellip;]<\/p>\n","protected":false},"author":502,"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_feature_clip_id":0,"_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":[],"class_list":["post-7752","post","type-post","status-publish","format-standard","hentry","category-web-architecture","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phns3A-212","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7752","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\/502"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=7752"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7752\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=7752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=7752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=7752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}