Variables in python | Full tutorial for beginners | Python Bootcamp

Introduction

Variables in python: In this post, you will learn what is Python variables and how do the variables actually works and also let’s see some examples and even the video format of the post below, do check it out ????????

Video:

What is Variable in Python ❓

The exact definition for variables is this one ????????

A Python variable is a reserved memory location to store values. In simple words, a variable in a python program gives data to the computer for processing.

How does the variables work❓????

In the previous post, I have talked about the len and input function and that code was really very confusing and really big.

But if the variable is used in that position it will be easier to identify and see the results.

For eg: Take a look at the below code

Now, the code seems to be very large and a little bit confusing. Let’s add a variable. And wait the object here is to get the string value using the len() function.

If you add variables the code looks something like this

Now, take both the code and run it in your compiler you will get the same result.

Let’s me open thonny and explain how it works in step by step

variables in python

So, I have entered the code the object here is to get the string value on what the user enters,

Over here name and length are the variables

Step1: name = input(“Please enter the value: “)

name is variable now when this code is printed the user should enter a value let’ assume the user enters ‘x’ then now the name will be x

name = x

Step2: length = len(name)

Here, I have entered another variable and the len function prints the string value only and inside that, I have added the previous variable name.

length: is new variable

len = length function prints length of the string

name = x

Now, let’s rearrange the code…

length = len(x)

Step3: print(length)

You no need to print name variable, if you print the name then you will see the name you entered, our objective here is to find the length of the string. So, we need to print the length variable.

Try it !!!

variables in python

Now you could see the value here is 1, For better understanding watch my youtube video at the top and I am sure you will be familiar with the variables.

Examples in variables

Try the below examples and I am sure you can do it and if not search in google and try it and keep trying it.

Example1:

Example2:


Also Read: Input function in python

Also Read: Len () function in python

Share your love
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions or brave browser to block ads. Please support us by disabling these ads blocker.Our website is made possible by displaying Ads hope you whitelist our site. We use very minimal Ads in our site