GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.dremendo.com — Variable in Python Programming with Example | Dremendo
?>
Announcements
No new announcements.
Python Programming Tutorial
Table of Contents
Variable in Python Programming with ExampleIn this lesson, we will learn about the variable in Python programming and its application, along with an example. What is VariableA variable is like a container that stores information which can be used and manipulated by a program. Variables have names, and these names are used to access the stored data.
Video Explanation
Click the button below to watch the explanation.
Please wait while the video is loading....
Think variable as a box having a name where you can keep a piece of data that you can use later in your program. You can also change the data stored in a variable whenever you want. A variable has three key concept and they are:
Let's see some real-life examples of variables. Image you are organizing a birthday party and need to keep track of various details. So let's see how you can store those details in variables. You need to store the total number of guest coming to the party. You can use Variable Name:
You need to store the name of the person whose birthday it is.
You need to remember the date of the party.
You need to keep track of how much money you have for the party.
You need to know if the party will be held indoors.
How to Declare Variable in PythonUnlike other programming languages like C, C++ or Java, Python has no command for declaring a variable. A variable is created in Python the moment we assign a value to it. Let's see some examples for more understanding.
Example 1
To declare an integer and float variable in Python.
Here, we have declared a variable x and assigned it the value 5, making it an integer variable. We can reuse the same variable to store a different type of value. As you can see on the second line, the same variable x is now used to store the float value 4.23, so the variable x now becomes a float variable. An integer variable is used to store whole numbers, such as 56, 8, and 493, which do not have a decimal part. A float variable, on the other hand, is used to store numbers with a decimal point, such as 2.3, 18.12, and 294.0.
Example 2
To declare a string variable in Python.
Here, we have declared a variable y and assigned it the string value "apple", making it a string variable.
Example 3
To declare a boolean variable in Python.
Here, we have declared a variable z and assigned it the boolean value True, making it a boolean variable. A boolean variable is used to store logical values such as True or False.
Example 4
To declare multiple variables and assign multiple values in a single line.
Or
Here, we have declared four variables: a, b, c, and d, and assigned them the values 5, 4.26, "apple", and True, respectively, in a single line. This can be done in two different ways: using commas (,) or semicolons (;). You can use whichever method you prefer.
Example 5
To declare same value in multiple variables in a single line.
Here, we have declared three variables: a, b, and c, and assigned the same value of 15 to all of them in a single line. Test Your KnowledgeAttempt the questions in the exercise to check whether you have understood the lesson clearly.
We care about your privacyDremendo uses cookies and similar technologies that are necessary for the site to work properly, understand how you interact with our website, and measure the effectiveness of our marketing. By clicking Accept All, you consent to the use of non-essential cookies and similar technologies for analytics, advertising, and ad measurement, as described in our Privacy Policy. Cookie PreferencesChoose which types of cookies Dremendo may use.
Necessary Cookies
Allow
Required for essential website functionality and security.
Analytics Cookies
Allow
Help us understand how visitors use Dremendo.
Marketing Cookies
Allow
Help us measure advertising performance and understand interactions with our advertisements.
Mentora
Question Asked: 0 / 20
Hi, I’m Mentora! I’m your personal AI tutor from Dremendo. Ask me anything, and I’ll help you understand it in a simple and easy way. |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |