{"id":98,"date":"2024-09-04T18:08:18","date_gmt":"2024-09-04T18:08:18","guid":{"rendered":"https:\/\/www.zframez.com\/articles\/?p=98"},"modified":"2024-10-16T15:01:31","modified_gmt":"2024-10-16T15:01:31","slug":"chapter-3-working-with-variables-in-python","status":"publish","type":"post","link":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-3-working-with-variables-in-python","title":{"rendered":"Chapter 3: Working with Variables in Python"},"content":{"rendered":"<body>\n<div class=\"table-of-contents\" style=\"background-color: #066095; color: white; padding: 10px; border-radius: 10px; margin-top: 20px; display: flex; justify-content: space-between; align-items: center; font-weight: 600;\">\n  <span style=\"flex: 1; text-align: left;\">\n    <a href=\"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-2-setting-up-python\" style=\"color: white; text-decoration: underline;\">\u25c0 Previous<\/a>\n  <\/span>\n  \n  <span style=\"flex: 1; text-align: center;\">\n    <a href=\"https:\/\/www.zframez.com\/articles\/python-tutorials\" style=\"color: white; text-decoration: underline;\">Python Tutorials<\/a>\n  <\/span>\n  \n  <span style=\"flex: 1; text-align: right;\">\n    <a href=\"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python\" style=\"color: white; text-decoration: underline;\">Next \u25b6<\/a>\n  <\/span>\n<\/div>\n\n\n\n\n<p class=\"has-text-align-left has-medium-font-size\">In Python, variables are one of the fundamental concepts you\u2019ll work with. They allow you to store data that your programs can manipulate and use. In this chapter, we\u2019ll explore what variables are, how to check the Python version you\u2019re using, and the different ways you can assign values to variables. By the end of this chapter, you\u2019ll be comfortable working with variables and ready to use them in your Python programs.<\/p>\n\n\n\n<div style=\"background: linear-gradient(to right, #ADD8E6, #8A2BE2); padding: 10px; border-radius: 10px; font-weight: 600; color: black;\">\n  <h3 style=\"text-align: center; margin-top: 0;\">Table of Contents<\/h3>\n  <ul style=\"padding-left: 20px;\">\n    <li><a href=\"#Getting-Python-Version\" style=\"color: black;\">Getting Python Version<\/a><\/li>\n    <li><a href=\"#What-is-a-Variable\" style=\"color: black;\">What is a Variable?<\/a><\/li>\n    <li><a href=\"#Different-Ways-to-Assign-Values-to-Variables\" style=\"color: black;\">Different Ways to Assign Values to Variables<\/a><\/li>\n  <\/ul>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-default\">\n\n\n\n<p class=\"has-large-font-size\" id=\"Getting-Python-Version\"><strong>Getting Python Version<\/strong><\/p>\n\n\n\n<p>Before starting with Python basics, it\u2019s important to ensure that you have Python installed correctly on your system. One of the first things you might want to do is check the version of Python you have installed. This is especially useful if you\u2019re working with features that may differ between versions of Python.<\/p>\n\n\n\n<p>\u00a0<strong>Checking the Python Version<\/strong>:<\/p>\n\n\n\n<p>You can check the Python version using the `sys` module, which provides access to some variables used or maintained by the Python interpreter.<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-333173743beb2523d57e094b55f0f0d7\"><code>import sys\nprint (sys.version)<\/code><\/pre>\n\n\n\n<p>Try the code yourself: <\/p>\n\n\n\n<div style=\"text-align: center;\">\n<iframe loading=\"lazy\" src=\"https:\/\/trinket.io\/embed\/python3\/82380e1426?showInstructions=true\" width=\"100%\" height=\"200\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" allowfullscreen><\/iframe>\n<\/div>\n\n\n\n<p><strong>Code Explanation:<\/strong><\/p>\n\n\n\n<p>\u201c<strong><em>import sys<\/em><\/strong>\u201c<\/p>\n\n\n\n<p>The <code>import<\/code> statement is used to include library files in a Python script. If you have written C programs before, you might have used <code>#include &lt;stdio.h&gt;<\/code> to include standard input-output library functions. The <code>import<\/code> statement in Python serves a similar purpose. This line imports the `sys` module, which contains system-specific parameters and functions.<\/p>\n\n\n\n<p>\u201c<strong><em>print(sys.version)<\/em><\/strong>\u201c<\/p>\n\n\n\n<p>This line prints the version of Python that is currently running.<\/p>\n\n\n\n<p><strong>Example Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">3.10.9 (main, Jan 23 2023, 22:32:48) [GCC 10.2.1 20210110]<\/pre>\n\n\n\n<p>This output shows that Python version 3.10.9 is installed, and it was built on September 23, 2023.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\">\n\n\n\n<p>Now that we\u2019ve ensured Python is installed and working correctly, let\u2019s move on to understanding variables.<\/p>\n\n\n\n<h1 class=\"wp-block-heading has-large-font-size\" id=\"What-is-a-Variable\"><strong>What is a Variable?<\/strong><\/h1>\n\n\n\n<p> A variable is used to store data and work with it in your programs. For example, you can store numbers, strings (words or sentences), lists, and other types of data in variables. When you create a variable, you reserve some space in memory to hold that value. The interpreter allocates memory space for the variable based on the type of value assigned to it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-large-font-size\"><strong>Rules for Creating Variables<\/strong><\/h3>\n\n\n\n<p>When naming variables in Python, there are several rules and best practices to follow:<\/p>\n\n\n\n<p><strong>1. Variable Names Must Start with a Letter or an Underscore:<\/strong><\/p>\n\n\n\n<p>\u00a0A variable name can start with a lowercase (`a-z`) or uppercase (`A-Z`) letter or an underscore (`_`).<\/p>\n\n\n\n<p><strong>Example:<\/strong> `name`, `_name`, `Name`<\/p>\n\n\n\n<p><strong>2. Subsequent Characters Can Be Letters, Numbers, or Underscores:<\/strong><\/p>\n\n\n\n<p>After the first character, variable names can include numbers (`0-9`), but the first character cannot be a number.<\/p>\n\n\n\n<p><strong>Example:<\/strong> `name1`, `first_name`, `_name2`<\/p>\n\n\n\n<p><strong>3. Case Sensitivity:<\/strong><\/p>\n\n\n\n<p>Variable names are case-sensitive in Python. This means `name`, `Name`, and `NAME` would be considered three different variables.<\/p>\n\n\n\n<p><strong>4. Reserved Words or Keywords Cannot Be Used as Variable Names:<\/strong><\/p>\n\n\n\n<p>Python has a set of reserved words or keywords that cannot be used as variable names. Examples include `if`, `else`, `for`, `while`, `class`, `def`, etc.<\/p>\n\n\n\n<p>Here are some examples demonstrating the rules for creating variables:<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-a1ec6bcca3182f67a5bd6a18ae6ba496\"><code># Valid variable names\nname = \"Peter\"\n_name = \"Jack\"\nname1 = \"Cole\"\nfirst_name = \"Owen\"\n\n# Case sensitivity\nname = \"Peter\"\nName = \"Jack\"\nNAME = \"Cole\"\n\nprint(name)  # Output: Peter\nprint(Name)  # Output: Jack\nprint(NAME)  # Output: Cole\n\n# Using descriptive names\nage = 25\nfirst_name = \"Owen\"\nheight_in_cm = 180\n\n# Invalid variable names\n1name = \"Invalid\"     # Starts with a number\nfirst-name = \"Invalid\" # Contains a hyphen\nif = 10               # Uses a reserved keyword\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\" id=\"Different-Ways-to-Assign-Values-to-Variables\"><strong>Different Ways to Assign Values to Variables<\/strong><\/h2>\n\n\n\n<p>In Python, there are several ways to assign values to variables. This flexibility allows for more concise and readable code. Here are some common methods to assign values to variables.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-large-font-size\"><strong>Simple Assignment<\/strong><\/h3>\n\n\n\n<p>As you have seen in the previous examples, you can assign a value to a variable using the equals (<code>=<\/code>) sign.<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-2770a48735b2ed8cf088328b60f8e884\"><code>a = 10\nprint (a)  # Output : 10\ntemp = 20\nprint (temp) # Output : 20\nname = \"peter\"\nprint (name) # Output : peter<\/code><\/pre>\n\n\n\n<p>In the above code we have three variables , \u201ca\u201d , \u201ctemp\u201d and \u201cname\u201d , the values of these variables are 10 , 20 and \u201cpeter\u201d.  <\/p>\n\n\n\n<p>Note: In Python, we don\u2019t have to specify the type of a variable before using it. Programming languages like C, C++, and Java require the data type to be declared first. In Python, a simple assignment operation (<code>=<\/code>) is enough to create a variable and assign data to it.<\/p>\n\n\n\n<p>Try the code yourself:<\/p>\n\n\n\n<div style=\"text-align: center;\">\n<iframe loading=\"lazy\" src=\"https:\/\/trinket.io\/embed\/python3\/ce8c3918a9\" width=\"100%\" height=\"250\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" allowfullscreen><\/iframe>\n<\/div>\n\n\n\n<h3 class=\"wp-block-heading has-large-font-size\">\u00a0<strong>2. Multiple Assignment<\/strong><\/h3>\n\n\n\n<p>You can assign values to multiple variables in a single line.<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-c432cfe1a38b3e4c9b7e4acb9ddb7e4a\"><code>a, b = 10, 20\nprint (a, b)  # Output : 10 20<\/code><\/pre>\n\n\n\n<p>Here, `a` is assigned the value `10`, and `b` is assigned the value `20`.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-large-font-size\"><strong>3. Chain Assignment<\/strong><\/h3>\n\n\n\n<p>You can assign the same value to multiple variables simultaneously.<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-834fe4375721c60d9ac14f5a9d29eb4e\"><code>x =  y = z  = 100\nprint (x, y, z)   # Output : 100 100 100<\/code><\/pre>\n\n\n\n<p>`In this case, `x`, `y`, and `z` are all assigned the value `10`.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-large-font-size\">\u00a0<strong>4.Mixed Assignment<\/strong><\/h3>\n\n\n\n<p>You can also assign different types of values to multiple variables in one line.<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-0f1a065d914978040491c0c1c68c51b8\"><code>name , age = \"peter\", 20\nprint (name, age)  # Output : peter 20<\/code><\/pre>\n\n\n\n<p>Here, \u201cname\u201d  is assigned the value `peter` (a string), and `age` is assigned the value \u201c20\u201d (an integer).<\/p>\n\n\n\n<p>Try the code :<\/p>\n\n\n\n<div style=\"text-align: center;\">\n<iframe loading=\"lazy\" src=\"https:\/\/trinket.io\/embed\/python3\/2ba4e18e18\" width=\"100%\" height=\"250\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" allowfullscreen><\/iframe>\n<\/div>\n\n\n\n<p><strong>Notes:<\/strong><\/p>\n\n\n\n<p>1. a = 10  and a = \u201910\u2019 are not the same. In the first command, the type of `a` is an integer, while in the second, `a` is a string. <\/p>\n\n\n\n<p>2. You can use single quotes, double quotes, or triple quotes to create strings. There is no difference in functionality between single and double quotes in Python.<\/p>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\"><strong>Different ways of<\/strong> <strong>Creating Strings:<\/strong><\/h2>\n\n\n\n<p>You can assign string values to variables using single quotes (`\u2019`), double quotes (`\u201d`), or triple quotes (`\u201d\u2019` or `\u201d\u201d\u201d`).<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-8092c32d1fdd2e13b92ffee37605786c\"><code>a = 'hello'\nb = \"hello\"\nc = 'hello world'\nd = \"hello world\"\nprint (a,b)   # Output : hello hello\nprint (c, d)  # Output : hello world hello world<\/code><\/pre>\n\n\n\n<p>In Python, there is no difference between using single quotes and double quotes when creating strings, as shown in above examples.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-large-font-size\"><strong>Creating<\/strong> <strong>Multi-line Strings<\/strong>:<\/h3>\n\n\n\n<p>Single quotes or double quotes can be used to assign a word or a single line to a variable. You can use triple single quotes (`\u201d\u2019`) or triple double quotes (`\u201d\u201d\u201d`) to create multi-line strings, as shown in the below example<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-a02fa1e60494b5be3ea6d2e4a38b6a92\"><code>a = '''Interface eth0 is up\nIP is 192.168.1.1\nMac is 00:11:22:33:44:55'''\n\nb = \"\"\"Interface eth0 is up\nIP is 192.168.1.1\nMac is 00:11:22:33:44:55\"\"\"<\/code><\/pre>\n\n\n\n<p>Try the code:<\/p>\n\n\n\n<div style=\"text-align: center;\">\n<iframe loading=\"lazy\" src=\"https:\/\/trinket.io\/embed\/python3\/7d59ed9875\" width=\"100%\" height=\"250\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" allowfullscreen><\/iframe>\n<\/div>\n\n\n\n<p>These different ways of assigning values to variables in Python allow for flexible and readable code. Understanding how to use variables effectively is fundamental to programming in Python.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\">\n\n\n\n<div class=\"table-of-contents\" style=\"background-color: #066095; color: white; padding: 10px; border-radius: 10px; margin-top: 20px; display: flex; justify-content: space-between; align-items: center; font-weight: 600;\">\n  <span style=\"flex: 1; text-align: left;\">\n    <a href=\"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-2-setting-up-python\" style=\"color: white; text-decoration: underline;\">\u25c0 Previous<\/a>\n  <\/span>\n  \n  <span style=\"flex: 1; text-align: center;\">\n    <a href=\"https:\/\/www.zframez.com\/articles\/python-tutorials\" style=\"color: white; text-decoration: underline;\">Python Tutorials<\/a>\n  <\/span>\n  \n  <span style=\"flex: 1; text-align: right;\">\n    <a href=\"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python\" style=\"color: white; text-decoration: underline;\">Next \u25b6<\/a>\n  <\/span>\n<\/div>\n\n\n\n\n<p><\/p>\n<\/body>","protected":false},"excerpt":{"rendered":"<p>\u25c0 Previous Python Tutorials Next \u25b6 In Python, variables are one of the fundamental concepts you\u2019ll work with. They allow you to store data that your programs can manipulate and use. In this chapter, we\u2019ll explore what variables are, how to check the Python version you\u2019re using, and the different ways you can assign values [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":731,"comment_status":"open","ping_status":"open","sticky":false,"template":"wp-custom-template-post-with-sidebar2","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[46],"tags":[246,247,248,57,238,251,47,250,249,252],"class_list":["post-98","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-tutorials","tag-assigning-variables-in-python","tag-data-storage-in-python","tag-programming-concepts","tag-python-basics","tag-python-for-beginners","tag-python-programs","tag-python-tutorial","tag-python-variables","tag-python-version","tag-variables-in-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Chapter 3: Working with Variables in Python - Tutorials<\/title>\n<meta name=\"description\" content=\"Learn what variables are in Python, how to check your Python version, and explore different ways to assign values to variables.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-3-working-with-variables-in-python\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Basics: Understanding Variables and Assigning Values\" \/>\n<meta property=\"og:description\" content=\"Explore Python variables, a fundamental concept that lets your programs store and manipulate data. Learn how to assign values and check your Python version.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-3-working-with-variables-in-python\" \/>\n<meta property=\"og:site_name\" content=\"Tutorials\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/zframez\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-04T18:08:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-16T15:01:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/Understanding-Python-variables.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"684\" \/>\n\t<meta property=\"og:image:height\" content=\"457\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"sajith achipra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@zframez\" \/>\n<meta name=\"twitter:site\" content=\"@zframez\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"sajith achipra\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-3-working-with-variables-in-python#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-3-working-with-variables-in-python\"},\"author\":{\"name\":\"sajith achipra\",\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/#\\\/schema\\\/person\\\/8b3b88007644501771d2452d3cc80f41\"},\"headline\":\"Chapter 3: Working with Variables in Python\",\"datePublished\":\"2024-09-04T18:08:18+00:00\",\"dateModified\":\"2024-10-16T15:01:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-3-working-with-variables-in-python\"},\"wordCount\":898,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-3-working-with-variables-in-python#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/www.zframez.com\\\/articles\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/Understanding-Python-variables.jpg?fit=684%2C457&ssl=1\",\"keywords\":[\"Assigning Variables in Python\",\"Data Storage in Python\",\"Programming Concepts\",\"python basics\",\"Python for Beginners\",\"Python Programs\",\"python tutorial\",\"Python Variables\",\"Python Version\",\"Variables in Python\"],\"articleSection\":[\"python tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-3-working-with-variables-in-python#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-3-working-with-variables-in-python\",\"url\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-3-working-with-variables-in-python\",\"name\":\"Chapter 3: Working with Variables in Python - Tutorials\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-3-working-with-variables-in-python#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-3-working-with-variables-in-python#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/www.zframez.com\\\/articles\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/Understanding-Python-variables.jpg?fit=684%2C457&ssl=1\",\"datePublished\":\"2024-09-04T18:08:18+00:00\",\"dateModified\":\"2024-10-16T15:01:31+00:00\",\"description\":\"Learn what variables are in Python, how to check your Python version, and explore different ways to assign values to variables.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-3-working-with-variables-in-python#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-3-working-with-variables-in-python\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-3-working-with-variables-in-python#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/www.zframez.com\\\/articles\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/Understanding-Python-variables.jpg?fit=684%2C457&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/www.zframez.com\\\/articles\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/Understanding-Python-variables.jpg?fit=684%2C457&ssl=1\",\"width\":684,\"height\":457,\"caption\":\"Exploring variables in Python with a hands-on coding setup.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-3-working-with-variables-in-python#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Tutorials\",\"item\":\"https:\\\/\\\/www.zframez.com\\\/articles\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Chapter 3: Working with Variables in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/#website\",\"url\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/\",\"name\":\"zframez tutorials\",\"description\":\"Learn networking bit by bit\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/#organization\",\"name\":\"zframez technologies\",\"url\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/www.zframez.com\\\/articles\\\/wp-content\\\/uploads\\\/2024\\\/07\\\/zframez-logo.jpg?fit=864%2C864&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/www.zframez.com\\\/articles\\\/wp-content\\\/uploads\\\/2024\\\/07\\\/zframez-logo.jpg?fit=864%2C864&ssl=1\",\"width\":864,\"height\":864,\"caption\":\"zframez technologies\"},\"image\":{\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/zframez\\\/\",\"https:\\\/\\\/x.com\\\/zframez\",\"https:\\\/\\\/www.instagram.com\\\/zframez_technologies\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/#\\\/schema\\\/person\\\/8b3b88007644501771d2452d3cc80f41\",\"name\":\"sajith achipra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3d9f27c5311500982b6f19d03d0506f1c328f30f51d8d5f73f46577687fd81f8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3d9f27c5311500982b6f19d03d0506f1c328f30f51d8d5f73f46577687fd81f8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3d9f27c5311500982b6f19d03d0506f1c328f30f51d8d5f73f46577687fd81f8?s=96&d=mm&r=g\",\"caption\":\"sajith achipra\"},\"sameAs\":[\"http:\\\/\\\/www.zframez.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Chapter 3: Working with Variables in Python - Tutorials","description":"Learn what variables are in Python, how to check your Python version, and explore different ways to assign values to variables.","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:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-3-working-with-variables-in-python","og_locale":"en_US","og_type":"article","og_title":"Python Basics: Understanding Variables and Assigning Values","og_description":"Explore Python variables, a fundamental concept that lets your programs store and manipulate data. Learn how to assign values and check your Python version.","og_url":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-3-working-with-variables-in-python","og_site_name":"Tutorials","article_publisher":"https:\/\/www.facebook.com\/zframez\/","article_published_time":"2024-09-04T18:08:18+00:00","article_modified_time":"2024-10-16T15:01:31+00:00","og_image":[{"width":684,"height":457,"url":"https:\/\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/Understanding-Python-variables.jpg","type":"image\/jpeg"}],"author":"sajith achipra","twitter_card":"summary_large_image","twitter_creator":"@zframez","twitter_site":"@zframez","twitter_misc":{"Written by":"sajith achipra","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-3-working-with-variables-in-python#article","isPartOf":{"@id":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-3-working-with-variables-in-python"},"author":{"name":"sajith achipra","@id":"https:\/\/www.zframez.com\/articles\/#\/schema\/person\/8b3b88007644501771d2452d3cc80f41"},"headline":"Chapter 3: Working with Variables in Python","datePublished":"2024-09-04T18:08:18+00:00","dateModified":"2024-10-16T15:01:31+00:00","mainEntityOfPage":{"@id":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-3-working-with-variables-in-python"},"wordCount":898,"commentCount":0,"publisher":{"@id":"https:\/\/www.zframez.com\/articles\/#organization"},"image":{"@id":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-3-working-with-variables-in-python#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/Understanding-Python-variables.jpg?fit=684%2C457&ssl=1","keywords":["Assigning Variables in Python","Data Storage in Python","Programming Concepts","python basics","Python for Beginners","Python Programs","python tutorial","Python Variables","Python Version","Variables in Python"],"articleSection":["python tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-3-working-with-variables-in-python#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-3-working-with-variables-in-python","url":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-3-working-with-variables-in-python","name":"Chapter 3: Working with Variables in Python - Tutorials","isPartOf":{"@id":"https:\/\/www.zframez.com\/articles\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-3-working-with-variables-in-python#primaryimage"},"image":{"@id":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-3-working-with-variables-in-python#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/Understanding-Python-variables.jpg?fit=684%2C457&ssl=1","datePublished":"2024-09-04T18:08:18+00:00","dateModified":"2024-10-16T15:01:31+00:00","description":"Learn what variables are in Python, how to check your Python version, and explore different ways to assign values to variables.","breadcrumb":{"@id":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-3-working-with-variables-in-python#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-3-working-with-variables-in-python"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-3-working-with-variables-in-python#primaryimage","url":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/Understanding-Python-variables.jpg?fit=684%2C457&ssl=1","contentUrl":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/Understanding-Python-variables.jpg?fit=684%2C457&ssl=1","width":684,"height":457,"caption":"Exploring variables in Python with a hands-on coding setup."},{"@type":"BreadcrumbList","@id":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-3-working-with-variables-in-python#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Tutorials","item":"https:\/\/www.zframez.com\/articles"},{"@type":"ListItem","position":2,"name":"Chapter 3: Working with Variables in Python"}]},{"@type":"WebSite","@id":"https:\/\/www.zframez.com\/articles\/#website","url":"https:\/\/www.zframez.com\/articles\/","name":"zframez tutorials","description":"Learn networking bit by bit","publisher":{"@id":"https:\/\/www.zframez.com\/articles\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.zframez.com\/articles\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.zframez.com\/articles\/#organization","name":"zframez technologies","url":"https:\/\/www.zframez.com\/articles\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.zframez.com\/articles\/#\/schema\/logo\/image\/","url":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/07\/zframez-logo.jpg?fit=864%2C864&ssl=1","contentUrl":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/07\/zframez-logo.jpg?fit=864%2C864&ssl=1","width":864,"height":864,"caption":"zframez technologies"},"image":{"@id":"https:\/\/www.zframez.com\/articles\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/zframez\/","https:\/\/x.com\/zframez","https:\/\/www.instagram.com\/zframez_technologies\/"]},{"@type":"Person","@id":"https:\/\/www.zframez.com\/articles\/#\/schema\/person\/8b3b88007644501771d2452d3cc80f41","name":"sajith achipra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3d9f27c5311500982b6f19d03d0506f1c328f30f51d8d5f73f46577687fd81f8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3d9f27c5311500982b6f19d03d0506f1c328f30f51d8d5f73f46577687fd81f8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3d9f27c5311500982b6f19d03d0506f1c328f30f51d8d5f73f46577687fd81f8?s=96&d=mm&r=g","caption":"sajith achipra"},"sameAs":["http:\/\/www.zframez.com"]}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/Understanding-Python-variables.jpg?fit=684%2C457&ssl=1","jetpack-related-posts":[{"id":110,"url":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python","url_meta":{"origin":98,"position":0},"title":"Chapter 4: Mastering the Print Function in Python","author":"sajith achipra","date":"September 4, 2024","format":false,"excerpt":"\u25c0 Previous Python Tutorials Next \u25b6 The print function is one of the most essential tools in Python, allowing you to display information and debug your code effectively. In this chapter, we\u2019ll learn the basics of print statements and explore how to print with descriptive text, use formatted string literals\u2026","rel":"","context":"In &quot;python tutorials&quot;","block_context":{"text":"python tutorials","link":"https:\/\/www.zframez.com\/articles\/category\/python-tutorials"},"img":{"alt_text":"Screenshot of Python interpreter mode displaying a print('Hello World!') statement","src":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/print-function-.png?fit=1200%2C675&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/print-function-.png?fit=1200%2C675&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/print-function-.png?fit=1200%2C675&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/print-function-.png?fit=1200%2C675&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/print-function-.png?fit=1200%2C675&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":913,"url":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-10-python-functions-variable-scopes-and-lambda-expressions","url_meta":{"origin":98,"position":1},"title":"Chapter 10: Python Functions, Variable Scopes, and Lambda Expressions","author":"sajith achipra","date":"September 15, 2024","format":false,"excerpt":"\u25c0 Previous Python Tutorials Next \u25b6 Understanding Functions, Variable Scopes, and Lambda Functions in Python In this chapter, we\u2019ll go through functions, one of the core building blocks in Python. Functions allow you to organize code, reuse logic, and make your programs cleaner and more efficient. In this chapter, we\u2019ll\u2026","rel":"","context":"In &quot;python tutorials&quot;","block_context":{"text":"python tutorials","link":"https:\/\/www.zframez.com\/articles\/category\/python-tutorials"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":83,"url":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-1-introduction-to-python-programming","url_meta":{"origin":98,"position":2},"title":"Chapter 1: Introduction to Python Programming","author":"sajith achipra","date":"September 4, 2024","format":false,"excerpt":"\u25c0 Previous Python Tutorials Next \u25b6 In this Python tutorial, we'll explore Python's origins, key milestones, and its standout features and benefits. Whether you're new to programming or looking to expand your skills, this guide will provide you with a solid foundation in Python. If you want to understand why\u2026","rel":"","context":"In &quot;python tutorials&quot;","block_context":{"text":"python tutorials","link":"https:\/\/www.zframez.com\/articles\/category\/python-tutorials"},"img":{"alt_text":"Table filled with Python-related materials, including a computer displaying Python code, a Python textbook, and notes about Python","src":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/working-with-python.webp?fit=1024%2C1024&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/working-with-python.webp?fit=1024%2C1024&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/working-with-python.webp?fit=1024%2C1024&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/working-with-python.webp?fit=1024%2C1024&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":901,"url":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-6-python-while-and-for-loops-examples-and-explanations","url_meta":{"origin":98,"position":3},"title":"Chapter 6: Python While and For Loops: Examples and Explanations","author":"sajith achipra","date":"September 15, 2024","format":false,"excerpt":"\u25c0 Previous Python Tutorials Next \u25b6 Python While and For Loops In this chapter of our Python tutorial series, we will explore two essential looping structures in Python: while loops and for loops. Loops are a fundamental part of programming, allowing you to execute a block of code repeatedly under\u2026","rel":"","context":"In &quot;python tutorials&quot;","block_context":{"text":"python tutorials","link":"https:\/\/www.zframez.com\/articles\/category\/python-tutorials"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":90,"url":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-2-setting-up-python","url_meta":{"origin":98,"position":4},"title":"Chapter 2: Setting Up Python","author":"sajith achipra","date":"September 4, 2024","format":false,"excerpt":"\u25c0 Previous Python Tutorials Next \u25b6 Before you can start writing and running Python code, you\u2019ll need to set up Python on your computer. In this chapter, we\u2019ll guide you through the process of installing Python on Windows, macOS, and Linux. We\u2019ll also explain what an Integrated Development Environment (IDE)\u2026","rel":"","context":"In &quot;python tutorials&quot;","block_context":{"text":"python tutorials","link":"https:\/\/www.zframez.com\/articles\/category\/python-tutorials"},"img":{"alt_text":"Screenshot of the official Python download page, highlighting the process of setting up Python.","src":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/download-and-install-python.png?fit=1200%2C499&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/download-and-install-python.png?fit=1200%2C499&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/download-and-install-python.png?fit=1200%2C499&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/download-and-install-python.png?fit=1200%2C499&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/download-and-install-python.png?fit=1200%2C499&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":751,"url":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-5-python-conditional-statements-if-else-and-elif","url_meta":{"origin":98,"position":5},"title":"Chapter 5:Python Conditional Statements: if, else, and elif","author":"sajith achipra","date":"September 11, 2024","format":false,"excerpt":"\u25c0 Previous Python Tutorials Next \u25b6 Table of Contents Introduction to Python `if` and `else` Understanding Python `if` Syntax Multiple Lines of Code in an `if` Statement Using `else` with `if` How does Python know when the `if` code block is finished? Using the `pass` Statement Checking Odd and Even\u2026","rel":"","context":"In &quot;python tutorials&quot;","block_context":{"text":"python tutorials","link":"https:\/\/www.zframez.com\/articles\/category\/python-tutorials"},"img":{"alt_text":"Block diagram illustrating an if expression and corresponding code block in Python, with a Python icon in the top right corner.","src":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/Python-conditional-statments-if-else.jpg?fit=1200%2C675&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/Python-conditional-statments-if-else.jpg?fit=1200%2C675&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/Python-conditional-statments-if-else.jpg?fit=1200%2C675&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/Python-conditional-statments-if-else.jpg?fit=1200%2C675&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/Python-conditional-statments-if-else.jpg?fit=1200%2C675&ssl=1&resize=1050%2C600 3x"},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/posts\/98","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/comments?post=98"}],"version-history":[{"count":5,"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/posts\/98\/revisions"}],"predecessor-version":[{"id":1079,"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/posts\/98\/revisions\/1079"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/media\/731"}],"wp:attachment":[{"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/media?parent=98"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/categories?post=98"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/tags?post=98"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}