Variable in programming is known as a memory portion which stores a specific value. Or you can simply think of as varables as containers which can store data. But how we use a variable and what kind of data can be stored on a variable.
You can creat a variable by simply writing a name and then assigning a value to it. Like this
Name = Value
The word "Name" is an identifier or name of variable.There are some rules for giving a bame to identifier.
RULES:
1. All alphabets, numbers and underscores( _ ) are allowed but name must start from alphabet or underscore not from number e.g
x, you, cow, abc123,_,_123,your_name etc
2. All other symbols are prohibited including space e.g 1as, .name, ,name, 1alter_, eger" etc
Now that you know what kind of names to choose so we will go to the next question what type of values are allowed.In python you don't need to mention the type of variable you are declairing but there are ways to distinguish between variables. We will study three types of values here which are integer, float and string.
INTEGER:
A variable can hold a whole number value called integer. This can be declaref as follows
Num = 12
Num2 = 34
Num3 = 400
Print (Num1, Num2, Num3)
>>>>>>12 34 400
FLOAT:
Float refers to decimel point value, double precision value or a value in fraction form. This can be written as follows
Float1 = 13.0
Float2 = 123.5
It can also incule vlues in scientific notation ie
Float3 = 10e2
Here, 10 e 2 refers to 10 raised to power 2.
ptint(Float1, Float2, Flaot3)
>>>>>>13 123.0 100.0
STRING:
A variable can have a value of alphabet, word, number or a whole sentence. This is called string and it is written in double or single quotes. It is declaired as follows
String1 = "What is your name"
String2 = "I am 18 years old"
String3 = "I have 2.99$"
print(String1)
print(String2)
print(String3)
>>>>>>What is your name
>>>>>>I am 18 years old
>>>>>>I have 2.99$
So, that is it for now there is much more to this topic but for now i think yhis is enough you can learn more about in other books.
YOU ARE READING
Python Guide for Beginners
RandomThis is an easy to learn and absolutly no programming experience is required.You can start learning by opening this book right now.
