Q. For each of the following data value, find the type, id and value (the three internal key-attributes of an object).



 
S. No Value Action The statement to be typed The Result returned by Python Shell
1. True Type this value in front of Python prompt >>> True >>> True
True

Why this result? (Explanation if any):

Explanation :- If we pass Boolean without variable then python return same Boolean.

S. No Value Action The statement to be typed The Result returned by Python Shell
2. True Assign this value to variable Val1 >>> val1 = True >>> val1
True

Why this result? (Explanation if any):

Explanation :- If we pass Boolean with variable then python return same Boolean.

S. No Value Action The statement to be typed The Result returned by Python Shell
3. True Check the type of this value using type () function >>> type (True) >>> type (True)
<class bool="">

Why this result? (Explanation if any):

Explanation :- Because {True} is Boolean.

S. No Value Action The statement to be typed The Result returned by Python Shell
4. - Check the type of variable Val1 using type () >>> type (val1) >>> type (val1)
<class 'bool'>

Why this result? (Explanation if any): [Why is the result of S. No. 3 and 4 same?]

Explanation :- Because val1 contain Boolean value. The result of S. No. 3 and 4 same because memory address of True is same.

Output :-

>>> val1 = True
>>> id(val1)
140722315257960
>>> id(True)
140722315257960
>>>
Note :- Memory address is different for different computers.


S. No Value Action The statement to be typed The Result returned by Python Shell
5. "True" Check the type of this value using type () function >>> type ('True') >>> type ('True')
<class 'str'>

Why this result? (Explanation if any):

Explanation :- Type “str” because “True” is in inverted comma. So, it is not Boolean.

S. No Value Action The statement to be typed The Result returned by Python Shell
6. 44 Check the type of this value using type () function >>> type (44) >>> type (44)
<class 'int'>

Why this result? (Explanation if any):

Explanation :- 44 is an integer number.

S. No Value Action The statement to be typed The Result returned by Python Shell
7. 44 Assign this value to variable Val2 >>> val2 = 44 Nothing returns

Why this result? (Explanation if any):

Explanation :- Python simply take value 44 in variable ‘val2’.

S. No Value Action The statement to be typed The Result returned by Python Shell
8. - Check the type of variable Val2 using type () >>> type (val2) >>> type (val2)
<class 'int'>

Why this result? (Explanation if any): [Why is the result of S. Nos. 6 and 8 same?]

Explanation :- Because memory address of value 44 is same.

Output :-

>>> val2 = 44
>>>val2
44
>>> 44
44
>>> id(val2)
2450948779664
>>> id(44)
2450948779664

Note :- Memory address is different for different computers.


S. No Value Action The statement to be typed The Result returned by Python Shell
9. - Assign value of variable Val2 to variable Val3 >>> val3 = val2 >>> val3 = val2
>>> val3
44

Why this result? (Explanation if any):

Explanation :- We can assign multiple variables for single value in python.

S. No Value Action The statement to be typed The Result returned by Python Shell
10. - Check the type of variable Val3 using type () function >>> type (val3) >>> type (val3)
<class 'int'>

Why this result? (Explanation if any):

Explanation :- Because variable val3 have an integer value.

S.No Value Action The statement to be typed The Result returned by Python Shell
11. 44 Check the id of this value using id () function >>> id(44) >>> id(44)
2450948779664

Why this result? (Explanation if any):

Explanation :- id () function return the memory address of number 44.

Note :- Memory address is different for different computers.

S. No Value Action The statement to be typed The Result returned by Python Shell
12. - Check the id of variable Val2 using id () function >>> id(val2) >>> id(val2)
2450948779664

Why this result? (Explanation if any): [Compare the result with S. No. 11]

Explanation :- Both 11 and 12 have same memory address so for their output is same.

Note :- Memory address is different for different computers.

S.No Value Action The statement to be typed The Result returned by Python Shell
13. - Check the id of variable Val3 using id () function >>> id(val3) >>> id(val3)
2450948779664

Why this result? (Explanation if any): [Compare the result with S. Nos. 11 and 12]

Explanation :- Both 11, 12 and 13 have same memory address so for their output is same.

Note :- Memory address is different for different computers.

S.No Value Action The statement to be typed The Result returned by Python Shell
14. 50 Check the type of this value using type () function >>> type (50) >>> type (50)
<class 'int'>

Why this result? (Explanation if any):

Explanation :- Because 50 is integer.

S.No Value Action The statement to be typed The Result returned by Python Shell
15. - Add 6 to variable Val3 >>> val3 + 6 >>> val3 + 6
50

Why this result? (Explanation if any):

Explanation :- Python simply add with value of variable val3 and 6 and give output 50.

S.No Value Action The statement to be typed The Result returned by Python Shell
16. - Check the id of variable Val3 using id () function >>> id(val3) >>> id(val3)
2450948779664

Why this result? (Explanation if any): [Compare the result with S. No. 14]

Explanation :- Python give memory address of value 44. Note :- Memory address is different for different computers.

S.No Value Action The statement to be typed The Result returned by Python Shell
17. ‘help’ Check the type of this value using id () function >>> id('help') >>> id('help')
2450949787568

Why this result? (Explanation if any):

Explanation :- id () function simply give the memory address of string ‘help’.

Note :- Memory address is different for different computers.

S.No Value Action The statement to be typed The Result returned by Python Shell
18. - Assign 'help' to a variables and check id () of s. >>> s = 'help' >>> s = 'help'
>>>id(s)
2450949787568

Why this result? (Explanation if any): [Compare the result with S. No. 17]

Explanation :- Both 17 & 18 have same memory address because their value is same. Note :- Memory address is different for different computers.

1 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post