Variable naming rules:
How variables are declared in Python?
C/C++/Java Python
int x = 10; x = 10
float y = 4.2; y = 4.2
String z = “hello”; z = “hello”
id(variable_name) :- Gives address of variable
type(variable_name) :- Gives type of variable
- Variables names must start with a letter or an underscore, such as:
- _underscore
- underscore_
- The remainder of your variable name may consist of letters, numbers and underscores.
- password1
- n00b
- un_der_scores
- Names are case sensitive.
- case_sensitive, CASE_SENSITIVE, and Case_Sensitive are each a different variable.
How variables are declared in Python?
C/C++/Java Python
int x = 10; x = 10
float y = 4.2; y = 4.2
String z = “hello”; z = “hello”
id(variable_name) :- Gives address of variable
type(variable_name) :- Gives type of variable
Case 1: Print the content, address and type of variable.
Case 2: Check 2 variables addresses with 2 different values.
Case 3: Check 3 variables addresses with same value.
All this 3 Cases are discussed in above video
Q If x=y=z=10 and we destroy ‘y’ then what happen?
Ans:
If y destroy still x and z will point to same memory location because Reference count for the object is now 2.
If Reference count becomes 0 then the object will get removed by garbage collector then that type of object is called as Unreferenced Object.