Q. Type the following statements and give the output in the space given below.

[You should be able to explain to your teacher about why some statements are yielding the same result and why some are giving different result?]

 
Statements Result Returned by Python Shell
1. a = 18
2. b = 7
3. c = b + 11
4. d = c - 11
5. id (7)
6. id (18)
7. id (a)
8. id (b)
9. id (c)
10. id(d)
11. d = 25 - b
12. id(d)
13. string1 = ‘Python’
14. string2 = string
15. id (string)
16. id (string2)
17. type (string1)
18. type (string2)
19. string3 = 'hello'
20. id (string3)
21. num1 = 1 + 0j
22. num2 = 1
23. type(num1)
24. type(num2)
25. id(num1)
26. id(num2)

Answer :-

 
Statements Result Returned by Python Shell
1. a = 18 >>> a = 18
>>> a
18
2. b = 7 >>> b = 7
>>> b
7
3. c = b + 11 >>> c = b + 11
>>> c
18
4. d = c - 11 >>> d = c - 11
>>> d
7
5. id (7) >>> id (7)
2058842171888
6. id (18) >>> id (18)
2058842172240
7. id (a) >>> id (a)
2058842172240
id of a (variable) and 18 (integer number) is same because their memory address is same.
8. id (b) >>> id (b)
2058842171888
id of b (variable) and 7 (integer number) is same because their memory address is same.
9. id (c) >>> id (c)
2058842172240
id of c (variable) and 18 (integer number) is same because their memory address is same.
10. id(d) >>> id(d)
2058842171888
id of d (variable) and 7 (integer number) is same because their memory address is same.
11. d = 25 - b >>> d = 25 - b
>>> d
18
12. id(d) >>> id(d)
2058842172240
Now id of d (variable) is changed because value of d (variable) is changed.
13. string1 = 'Python' >>> string1 = 'Python'
>>> string1
'Python'
14. string2 = string It will give error that is string is not defined.
15. id (string1) >>> id (string1)
2058843177648
16. id (string2) It will give error that is string2 is not defined.
17. type (string1) >>> type (string1)
<class 'str'>
18. type (string2) It will give error that is string2 is not defined.
19. string3 = 'hello' >>> string3 = 'hello'
>>> string3
'hello'
20. id (string3) >>> id (string3)
2058883254896
21. num1 = 1 + 0j >>> num1 = 1 + 0j
>>> num1
(1+0j)
22. num2 = 1 >>> num2 = 1
>>> num2
1
23. type(num1) >>> type(num1)
<class 'complex'>
24. type(num2) >>> type(num2)
<class 'int'>
25. id(num1) >>> id(num1)
2058882457488
26. id(num2) >>> id(num2)
2058842171696

5 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