Python Programming:-
In this tutorial, you will learn:-
Variables:-
In Python, a variable is considered as a tag that is tied to some value. In other words, variables are a type of container which holds some value. A variable name can be in alphanumeric type but not start with a number. For e.g: name1=100Python considered variables as an object
.
Variable assignment:
In python programming language there no need to declare or defined in advance as a case of another programming language.
Let, create a variable and assign value.
>>n=100
>>print(n)
>>100
so very easy you can assign any value in a variable and print it using print() function which is already stored in python's library.
Multiple variable assignment:-
In other programming languages like c, c++,etc We need to declare and assign like this:
a=10;
b=10;
c=10;
and then print, but in python,we can assign value in only one line like this:
>>a=b=c=10;
>>print(a)
>>print(b)
>>print(c)
>>10
>>10
>>10
>>10
For example, suppose we take,
>>a=10
a ------Tag name
10
|
1002 ---------Address
>>Print(a)
10 ------- - output
type(a) ---by type function we find the type of variable
<class' int'> -------- type of datatype
id(a) ---by this id function we can get the address of the value
1002 -------address
So, in python "a" is a type of tag we can not say it variable in python it is just a tag that carries integer value.
As we know that in other programming languages a variable takes an address in memory, but in python the value takes an address.
And one more thing suppose if we take two types of the same value and try to take in a different variable like this :
And one more thing suppose if we take two types of the same value and try to take in a different variable like this :
>> a=10
>> b=10
So, in this situation 10 already takes one address, and when the interpreter read b's value it cannot give another address to b's 10, it just combines both a and b into one tag which has a value 10.
Rules for variable declaration:-
1. Every variable should start with alphabet or underscore (_)
2. No space is allowed in variable declaration.
3. Except underscore (_) no other special symbol is allowed in the middle of the variable declaration
4. A variable is written with a combination of letter, number, & any special character
For example:-
* a
* name
* abhi12
* _city
* codewith_abhi
* Codeswithabhi
so this is some variable declarations
Python |
0 comments:
Post a Comment
If you have any doubt, please let me know