{"id":442,"date":"2025-05-19T19:30:23","date_gmt":"2025-05-19T19:30:23","guid":{"rendered":"https:\/\/buhave.com\/courses\/?p=442"},"modified":"2026-06-06T11:26:12","modified_gmt":"2026-06-06T11:26:12","slug":"variables-data-types-and-operators","status":"publish","type":"post","link":"https:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/","title":{"rendered":"Variables, Data Types and Operators"},"content":{"rendered":"<h2>Variables and Naming Conventions<\/h2>\n<h3>What is a Variable?<\/h3>\n<p>A variable is a name that stores a value. Think of it as a labeled box where you can put data and use it later in your code. For a broader overview of Python basics, see <a href=\"https:\/\/buhave.com\/courses\/python\/introduction-to-python\/\">Introduction to Python<\/a>.<\/p>\n<p style=\"text-align: center\"><em>x = 5<\/em><br \/>\n<em>name = &#8220;Alice&#8221;<\/em><br \/>\n<em>is_logged_in = True<\/em><\/p>\n<ul>\n<li>You use the = symbol (assignment operator) to assign a value to a variable.<\/li>\n<li>Variables do not need a type declaration. Python figures it out automatically.<\/li>\n<\/ul>\n<p><strong>Why Use Variables?<\/strong><\/p>\n<ul>\n<li>To store user input<\/li>\n<li>To reuse values without repeating them<\/li>\n<li>To make your code more readable and maintainable<\/li>\n<\/ul>\n<p>To see variables in action within practical examples, explore <a href=\"https:\/\/buhave.com\/courses\/python\/loops-and-iteration-2\/\">Loops and Iteration<\/a>.<\/p>\n<p><strong>Examples:<\/strong><\/p>\n<p style=\"text-align: center\"><em>age = 25<\/em><br \/>\n<em>greeting = &#8220;Hello&#8221;<\/em><br \/>\n<em>pi = 3.14159<\/em><br \/>\n<em>is_admin = False<\/em><\/p>\n<p>You can also reassign values:<\/p>\n<p style=\"text-align: center\"><em>age = 30<\/em><\/p>\n<p><strong>Valid Variable Names<\/strong><\/p>\n<ul>\n<li>Must start with a letter (a\u2013z, A\u2013Z) or underscore (_)<\/li>\n<li>Can include letters, digits (0\u20139), and underscores<\/li>\n<li>Case-sensitive (age and Age are different)<\/li>\n<\/ul>\n<p style=\"text-align: center\"><em>my_name = &#8220;Sarah&#8221;<\/em><br \/>\n<em>_age = 20<\/em><br \/>\n<em>score2 = 99<\/em><\/p>\n<p><strong>Invalid Variable Names<\/strong><\/p>\n<p style=\"text-align: center\"><em>2cool = &#8220;nope&#8221; # starts with a number<\/em><br \/>\n<em>user-name = &#8220;error&#8221; # contains a dash<\/em><br \/>\n<em>class = &#8220;reserved&#8221; # &#8216;class&#8217; is a keyword<\/em><\/p>\n<p><strong>Best Practices (PEP8 Guidelines)<\/strong><\/p>\n<table style=\"width: 100%;border-collapse: collapse;font-family: Arial, sans-serif;margin: 20px 0\">\n<thead>\n<tr>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #000;font-weight: bold\"><strong>Element<\/strong><\/th>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #000;font-weight: bold\"><strong>Style<\/strong><\/th>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #000;font-weight: bold\"><strong>Example<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Variable names<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">snake_case<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>user_name<\/code>, <code>score_total<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Constants<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">ALL_CAPS<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>MAX_USERS = 10<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Avoid single letters<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Unless in loops<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Prefer <code>count<\/code> over <code>c<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Descriptive is better<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Be clear<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>email_address<\/code> &gt; <code>e<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Avoid These Mistakes<\/strong><\/p>\n<ul>\n<li>Don\u2019t name variables after built-in functions like list, str, input<\/li>\n<\/ul>\n<p style=\"text-align: center\"><em>input = &#8220;Hello&#8221; # Bad: overrides built-in input() function<\/em><\/p>\n<ul>\n<li>Don\u2019t use spaces or special characters<\/li>\n<\/ul>\n<p style=\"text-align: center\"><em>user name = &#8220;Bob&#8221; # invalid<\/em><\/p>\n<p><strong>Python Keywords (Can&#8217;t be Variable Names)<\/strong><\/p>\n<p>Here are a few reserved keywords you can&#8217;t use as variable names:<\/p>\n<p style=\"text-align: center\"><em>False, True, None, if, else, elif, for, while, class, def, try, except, with, return, import, as, pass, break, continue, and, or, not, in, is<\/em><\/p>\n<p><strong>Quick Exercise:<\/strong><\/p>\n<p>Which of these are valid variable names?<\/p>\n<p style=\"text-align: center\"><em>1. user_age = 20<\/em><br \/>\n<em>2. $salary = 50000<\/em><br \/>\n<em>3. full name = &#8220;Amy&#8221;<\/em><br \/>\n<em>4. _secret = &#8220;shhh&#8221;<\/em><br \/>\n<em>5. def = &#8220;define&#8221;<\/em><\/p>\n<p>Answers: 1 and 4 are valid.<\/p>\n<h2>Data types: int, float, str, bool<\/h2>\n<p>Python is a dynamically typed language, meaning you don\u2019t need to specify the data type \u2014 Python figures it out automatically. For a broader overview, see <a href=\"https:\/\/buhave.com\/courses\/python\/introduction-to-python\/\">Introduction to Python<\/a>.<\/p>\n<p>You can use the type() function to check the data type of any value or variable.<\/p>\n<p style=\"text-align: center\"><em>x = 10<\/em><br \/>\n<em>print(type(x)) # &lt;class &#8216;int&#8217;&gt;<\/em><\/p>\n<h3>Integer (int)<\/h3>\n<ul>\n<li>Whole numbers (positive or negative) without decimals<\/li>\n<li>Unlimited size (up to your machine&#8217;s memory)<\/li>\n<\/ul>\n<p style=\"text-align: center\"><em>age = 30<\/em><br \/>\n<em>year = 2026<\/em><br \/>\n<em>temperature = -5<\/em><\/p>\n<p style=\"text-align: center\"><em>type(age) # &lt;class &#8216;int&#8217;&gt;<\/em><\/p>\n<p><strong>You can do math with integers:<\/strong><\/p>\n<p style=\"text-align: center\"><em>a = 10<\/em><br \/>\n<em>b = 3<\/em><br \/>\n<em>print(a + b) # 13<\/em><br \/>\n<em>print(a &#8211; b) # 7<\/em><br \/>\n<em>print(a * b) # 30<\/em><br \/>\n<em>print(a \/\/ b) # 3 (floor division)<\/em><br \/>\n<em>print(a % b) # 1 (modulus)<\/em><br \/>\n<em>print(a ** b) # 1000 (exponent)<\/em><\/p>\n<h3>Float (float)<\/h3>\n<ul>\n<li>Numbers with decimal points<\/li>\n<li>Used for measurements, precise calculations, etc.<\/li>\n<\/ul>\n<p style=\"text-align: center\"><em>pi = 3.14159<\/em><br \/>\n<em>weight = 65.5<\/em><br \/>\n<em>gpa = 3.75<\/em><\/p>\n<p style=\"text-align: center\"><em>type(pi) # &lt;class &#8216;float&#8217;&gt;<\/em><\/p>\n<p>Be careful with floating point precision:<\/p>\n<p style=\"text-align: center\"><em>print(0.1 + 0.2) # 0.30000000000000004<\/em><\/p>\n<p>You can convert between int and float:<\/p>\n<p style=\"text-align: center\"><em>int(3.9) # 3<\/em><br \/>\n<em>float(4) # 4.0<\/em><\/p>\n<h3>String (str)<\/h3>\n<ul>\n<li>Text values wrapped in quotes<\/li>\n<li>Can use single &#8216;, double &#8220;, or triple &#8220;&#8221;&#8221; for multiline<\/li>\n<\/ul>\n<p style=\"text-align: center\"><em>name = &#8220;Alice&#8221;<\/em><br \/>\n<em>greeting = &#8216;Hello&#8217;<\/em><br \/>\n<em>quote = &#8220;&#8221;&#8221;Python is fun!&#8221;&#8221;&#8221;<\/em><\/p>\n<p style=\"text-align: center\"><em>type(name) # &lt;class &#8216;str&#8217;&gt;<\/em><\/p>\n<p><strong>String operations:<\/strong><\/p>\n<p style=\"text-align: center\"><em>full_name = &#8220;John&#8221; + &#8221; &#8221; + &#8220;Doe&#8221; # Concatenation<\/em><br \/>\n<em>print(len(full_name)) # Length of the string<\/em><br \/>\n<em>print(name.upper()) # &#8220;ALICE&#8221;<\/em><br \/>\n<em>print(name.lower()) # &#8220;alice&#8221;<\/em><br \/>\n<em>print(name[0]) # &#8220;A&#8221;<\/em><\/p>\n<p><strong>You can use f-strings for formatting:<\/strong><\/p>\n<p style=\"text-align: center\"><em>age = 25<\/em><br \/>\n<em>print(f&#8221;My age is {age}&#8221;)<\/em><\/p>\n<p>For more on string operations, see <a href=\"https:\/\/buhave.com\/courses\/python\/working-with-strings\/\">Working with Strings<\/a>.<\/p>\n<h3>Boolean (bool)<\/h3>\n<ul>\n<li>Only two values: True or False (capitalized)<\/li>\n<li>Used for conditions and logic<\/li>\n<\/ul>\n<p style=\"text-align: center\"><em>is_active = True<\/em><br \/>\n<em>is_admin = False<\/em><\/p>\n<p style=\"text-align: center\"><em>type(is_active) # &lt;class &#8216;bool&#8217;&gt;<\/em><\/p>\n<p><strong> Booleans often come from comparisons:<\/strong><\/p>\n<p style=\"text-align: center\"><em>print(5 &gt; 3) # True<\/em><br \/>\n<em>print(10 == 5) # False<\/em><\/p>\n<p><strong>Used in if statements:<\/strong><\/p>\n<p style=\"text-align: center\"><em>logged_in = True<\/em><\/p>\n<p style=\"text-align: center\"><em>if logged_in:<\/em><br \/>\n<em>print(&#8220;Welcome!&#8221;)<\/em><br \/>\n<em>else:<\/em><br \/>\n<em>print(&#8220;Please log in.&#8221;)<\/em><\/p>\n<p>To see how booleans drive decisions in code, check <a href=\"https:\/\/buhave.com\/courses\/python\/control-flow-2\/\">Control Flow<\/a>.<\/p>\n<p><strong>Type Conversion Summary:<\/strong><\/p>\n<table style=\"width: 100%;border-collapse: collapse;font-family: Arial, sans-serif;margin: 20px 0\">\n<thead>\n<tr>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #000;font-weight: bold\"><strong>Function<\/strong><\/th>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #000;font-weight: bold\"><strong>Converts to<\/strong><\/th>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #000;font-weight: bold\"><strong>Example<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>int()<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Integer<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>int(\"10\") \u2192 10<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>float()<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Float<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>float(\"3.14\") \u2192 3.14<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>str()<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">String<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>str(123) \u2192 \"123\"<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>bool()<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Boolean<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>bool(0) \u2192 False<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Empty values like 0, 0.0, &#8220;&#8221;, None, and [] are all considered False.<\/p>\n<h2>Type casting and input()<\/h2>\n<h3>What is Type Casting?<\/h3>\n<p>Type casting means converting one data type into another \u2014 for example, changing a string into an integer. For a quick refresher, see Introduction to Python.<\/p>\n<p><strong>Python has built-in functions to do this:<\/strong><\/p>\n<table style=\"width: 100%;border: 1px solid #ddd;border-collapse: collapse;font-family: Arial, sans-serif;margin: 20px 0\">\n<thead>\n<tr>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #ddd;font-weight: bold;border-right: 1px solid #ddd\"><strong>Function<\/strong><\/th>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #ddd;font-weight: bold;border-right: 1px solid #ddd\"><strong>Converts to<\/strong><\/th>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #ddd;font-weight: bold\"><strong>Example<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd\"><code>int()<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd\">Integer<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>int(\"10\") \u2192 10<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd\"><code>float()<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd\">Float<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>float(\"3.14\") \u2192 3.14<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd\"><code>str()<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd\">String<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>str(100) \u2192 \"100\"<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd\"><code>bool()<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd\">Boolean<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>bool(\"hi\") \u2192 True<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Examples of Type Casting:<\/strong><\/p>\n<p style=\"text-align: center\"><em>x = &#8220;25&#8221;<\/em><br \/>\n<em>y = int(x) # y becomes 25 (an int)<\/em><br \/>\n<em>print(x, type(x)) # &#8217;25&#8217; &lt;class &#8216;str&#8217;&gt;<\/em><br \/>\n<em>print(y, type(y)) # 25 &lt;class &#8216;int&#8217;&gt;<\/em><\/p>\n<p style=\"text-align: center\"><em>pi = &#8220;3.14&#8221;<\/em><br \/>\n<em>print(float(pi)) # 3.14<\/em><\/p>\n<p style=\"text-align: center\"><em>number = 99<\/em><br \/>\n<em>print(str(number)) # &#8217;99&#8217;<\/em><\/p>\n<h3>input() Function<\/h3>\n<p><strong>What is input()?<\/strong><\/p>\n<p>The input() function asks the user for input from the keyboard and always returns a string. For more on Python basics, see Introduction to Python.<\/p>\n<p style=\"text-align: center\"><em>name = input(&#8220;What is your name? &#8220;)<\/em><br \/>\n<em>print(&#8220;Hello, &#8221; + name)<\/em><\/p>\n<p><strong>Even if the user enters numbers, Python treats them as strings:<\/strong><\/p>\n<p style=\"text-align: center\"><em>age = input(&#8220;Enter your age: &#8220;)<\/em><br \/>\n<em>print(age, type(age)) # &#8217;25&#8217; &lt;class &#8216;str&#8217;&gt;<\/em><\/p>\n<p><strong>Using input() with Type Casting<\/strong><\/p>\n<p>To use the input as a number, you must cast it manually:<\/p>\n<p style=\"text-align: center\"><em># Get input and cast to int<\/em><br \/>\n<em>age = int(input(&#8220;Enter your age: &#8220;))<\/em><br \/>\n<em>print(age + 5) # Adds 5 to age<\/em><br \/>\n# Get input and cast to float<br \/>\nheight = float(input(&#8220;Enter your height in meters: &#8220;))<br \/>\nprint(&#8220;Your height + 0.1m =&#8221;, height + 0.1)<\/p>\n<p style=\"text-align: left\">Be careful! If the user enters non-numeric text when casting to int() or float(), it will cause an error.<\/p>\n<p><strong>Pro Tip:<\/strong> Add Input Validation (Optional Advanced)<\/p>\n<p style=\"text-align: center\"><em>age_input = input(&#8220;Enter your age: &#8220;)<\/em><\/p>\n<p style=\"text-align: center\"><em>if age_input.isdigit():<\/em><br \/>\n<em>age = int(age_input)<\/em><br \/>\n<em>print(f&#8221;You will be {age + 1} next year.&#8221;)<\/em><br \/>\n<em>else:<\/em><br \/>\n<em>print(&#8220;Please enter a valid number.&#8221;)<\/em><\/p>\n<p><strong>Summary:<\/strong><\/p>\n<table style=\"width: 100%;border-collapse: collapse;font-family: Arial, sans-serif;margin: 20px 0\">\n<thead>\n<tr>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #000;font-weight: bold\"><strong>Concept<\/strong><\/th>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #000;font-weight: bold\"><strong>Converts to<\/strong><\/th>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #000;font-weight: bold\"><strong>Example<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>int()<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Integer<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>int(\"10\") \u2192 10<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>float()<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Float<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>float(\"3.14\") \u2192 3.14<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>str()<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">String<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>str(100) \u2192 \"100\"<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>bool()<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Boolean<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>bool(\"hi\") \u2192 True<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Variables and Naming Conventions What is a Variable? A variable is a name that stores a value. Think of it [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":443,"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":""}},"footnotes":""},"categories":[9],"tags":[],"class_list":["post-442","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Variables, Data Types and Operators -<\/title>\n<meta name=\"description\" content=\"Variables, Data Types, and Operators introduce how to store, classify, and manipulate data in Python programs.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Variables, Data Types and Operators -\" \/>\n<meta property=\"og:description\" content=\"Variables, Data Types, and Operators introduce how to store, classify, and manipulate data in Python programs.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/\" \/>\n<meta property=\"og:site_name\" content=\"BUHAVE\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/BeYouHave\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/naveedsafdarawan\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-19T19:30:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-06T11:26:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Variables-Data-Types-Operators.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Naveed Safdar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Naveed Safdar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/variables-data-types-and-operators\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/variables-data-types-and-operators\\\/\"},\"author\":{\"name\":\"Naveed Safdar\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/person\\\/04fe0254e118521c9fbb3da39de5acca\"},\"headline\":\"Variables, Data Types and Operators\",\"datePublished\":\"2025-05-19T19:30:23+00:00\",\"dateModified\":\"2026-06-06T11:26:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/variables-data-types-and-operators\\\/\"},\"wordCount\":888,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/variables-data-types-and-operators\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/Variables-Data-Types-Operators.webp\",\"articleSection\":[\"Python Course\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/variables-data-types-and-operators\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/variables-data-types-and-operators\\\/\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/variables-data-types-and-operators\\\/\",\"name\":\"Variables, Data Types and Operators -\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/variables-data-types-and-operators\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/variables-data-types-and-operators\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/Variables-Data-Types-Operators.webp\",\"datePublished\":\"2025-05-19T19:30:23+00:00\",\"dateModified\":\"2026-06-06T11:26:12+00:00\",\"description\":\"Variables, Data Types, and Operators introduce how to store, classify, and manipulate data in Python programs.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/variables-data-types-and-operators\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/variables-data-types-and-operators\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/variables-data-types-and-operators\\\/#primaryimage\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/Variables-Data-Types-Operators.webp\",\"contentUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/Variables-Data-Types-Operators.webp\",\"width\":1200,\"height\":628,\"caption\":\"Variables, Data Types &amp; Operators\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/variables-data-types-and-operators\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Courses\",\"item\":\"https:\\\/\\\/buhave.com\\\/courses\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Course\",\"item\":\"https:\\\/\\\/buhave.com\\\/courses\\\/learn\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Variables, Data Types and Operators\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#website\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/\",\"name\":\"BUHAVE\",\"description\":\"Courses - Learn Online for Free\",\"publisher\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/buhave.com\\\/courses\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#organization\",\"name\":\"BUHAVE\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/buhave-course.webp\",\"contentUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/buhave-course.webp\",\"width\":375,\"height\":75,\"caption\":\"BUHAVE\"},\"image\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/BeYouHave\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/buhave\",\"https:\\\/\\\/www.youtube.com\\\/@buhave\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/person\\\/04fe0254e118521c9fbb3da39de5acca\",\"name\":\"Naveed Safdar\",\"description\":\"I\u2019m Naveed Safdar - SEO Manager with over 10 years of experience in SEO and Digital Marketing. I\u2019ve had the privilege of working with leading national and international companies including Grafdom, PakWheels, Systems Limited, Confiz, Educative, and Dubizzle Labs. My expertise spans technical SEO, content strategy, organic growth, and performance analytics - helping businesses improve visibility, traffic, and ROI.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/naveedsafdar\\\/\",\"https:\\\/\\\/www.facebook.com\\\/naveedsafdarawan\\\/\",\"https:\\\/\\\/www.youtube.com\\\/@naveedsafdar\"],\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/author\\\/naveed-safdar\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Variables, Data Types and Operators -","description":"Variables, Data Types, and Operators introduce how to store, classify, and manipulate data in Python programs.","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:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/","og_locale":"en_US","og_type":"article","og_title":"Variables, Data Types and Operators -","og_description":"Variables, Data Types, and Operators introduce how to store, classify, and manipulate data in Python programs.","og_url":"https:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/","og_site_name":"BUHAVE","article_publisher":"https:\/\/www.facebook.com\/BeYouHave\/","article_author":"https:\/\/www.facebook.com\/naveedsafdarawan\/","article_published_time":"2025-05-19T19:30:23+00:00","article_modified_time":"2026-06-06T11:26:12+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Variables-Data-Types-Operators.webp","type":"image\/webp"}],"author":"Naveed Safdar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Naveed Safdar","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/#article","isPartOf":{"@id":"https:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/"},"author":{"name":"Naveed Safdar","@id":"https:\/\/buhave.com\/courses\/#\/schema\/person\/04fe0254e118521c9fbb3da39de5acca"},"headline":"Variables, Data Types and Operators","datePublished":"2025-05-19T19:30:23+00:00","dateModified":"2026-06-06T11:26:12+00:00","mainEntityOfPage":{"@id":"https:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/"},"wordCount":888,"commentCount":0,"publisher":{"@id":"https:\/\/buhave.com\/courses\/#organization"},"image":{"@id":"https:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/#primaryimage"},"thumbnailUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Variables-Data-Types-Operators.webp","articleSection":["Python Course"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/","url":"https:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/","name":"Variables, Data Types and Operators -","isPartOf":{"@id":"https:\/\/buhave.com\/courses\/#website"},"primaryImageOfPage":{"@id":"https:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/#primaryimage"},"image":{"@id":"https:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/#primaryimage"},"thumbnailUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Variables-Data-Types-Operators.webp","datePublished":"2025-05-19T19:30:23+00:00","dateModified":"2026-06-06T11:26:12+00:00","description":"Variables, Data Types, and Operators introduce how to store, classify, and manipulate data in Python programs.","breadcrumb":{"@id":"https:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/#primaryimage","url":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Variables-Data-Types-Operators.webp","contentUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Variables-Data-Types-Operators.webp","width":1200,"height":628,"caption":"Variables, Data Types &amp; Operators"},{"@type":"BreadcrumbList","@id":"https:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Courses","item":"https:\/\/buhave.com\/courses\/"},{"@type":"ListItem","position":2,"name":"Python Course","item":"https:\/\/buhave.com\/courses\/learn\/python\/"},{"@type":"ListItem","position":3,"name":"Variables, Data Types and Operators"}]},{"@type":"WebSite","@id":"https:\/\/buhave.com\/courses\/#website","url":"https:\/\/buhave.com\/courses\/","name":"BUHAVE","description":"Courses - Learn Online for Free","publisher":{"@id":"https:\/\/buhave.com\/courses\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/buhave.com\/courses\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/buhave.com\/courses\/#organization","name":"BUHAVE","url":"https:\/\/buhave.com\/courses\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/buhave.com\/courses\/#\/schema\/logo\/image\/","url":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/03\/buhave-course.webp","contentUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/03\/buhave-course.webp","width":375,"height":75,"caption":"BUHAVE"},"image":{"@id":"https:\/\/buhave.com\/courses\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/BeYouHave\/","https:\/\/www.linkedin.com\/company\/buhave","https:\/\/www.youtube.com\/@buhave"]},{"@type":"Person","@id":"https:\/\/buhave.com\/courses\/#\/schema\/person\/04fe0254e118521c9fbb3da39de5acca","name":"Naveed Safdar","description":"I\u2019m Naveed Safdar - SEO Manager with over 10 years of experience in SEO and Digital Marketing. I\u2019ve had the privilege of working with leading national and international companies including Grafdom, PakWheels, Systems Limited, Confiz, Educative, and Dubizzle Labs. My expertise spans technical SEO, content strategy, organic growth, and performance analytics - helping businesses improve visibility, traffic, and ROI.","sameAs":["https:\/\/www.linkedin.com\/in\/naveedsafdar\/","https:\/\/www.facebook.com\/naveedsafdarawan\/","https:\/\/www.youtube.com\/@naveedsafdar"],"url":"https:\/\/buhave.com\/courses\/author\/naveed-safdar\/"}]}},"_links":{"self":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts\/442","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/comments?post=442"}],"version-history":[{"count":3,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts\/442\/revisions"}],"predecessor-version":[{"id":1117,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts\/442\/revisions\/1117"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/media\/443"}],"wp:attachment":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/media?parent=442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/categories?post=442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/tags?post=442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}