Type of variables in python


SUBMITTED BY: Guest

DATE: Dec. 15, 2013, 6:20 a.m.

FORMAT: Python

SIZE: 648 Bytes

HITS: 916

  1. # variable and types
  2. a = 10
  3. print (a, type(a),id(a)) # int
  4. b=a
  5. print (a, type(a),id(a)) # float
  6. a = True
  7. print (a, type(a),id(a)) # bool
  8. c = 3 + 4j
  9. print (c, type(c),id(c)) # complex
  10. a = "python"
  11. print (a, type(a),id(a)) # str
  12. a = [11, "a", 33, 44]
  13. a.remove(a[3])
  14. print (a, type(a),id(a),type(a[0]),type(a[1])) # list - similar to array
  15. a = (11, 22, 33, 44)
  16. print (a, type(a),id(a),id(a[0])) # tuple - similar to list; cannot be changed
  17. a = {11, 22, 33, 11,44}
  18. print (a, type(a),id(a)) # set
  19. a = {11 : 22, 7 : 44}
  20. print (a, type(a),id(a)) # dict
  21. a=[11,'q',3+4j]
  22. print(a)

comments powered by Disqus