Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. #PRENOTES
  2. #=============================================================================
  3. #Installation of python2.7
  4. #print()
  5.  
  6.  
  7. #DATA TYPES
  8. #=============================================================================
  9. def f():
  10. print("This is a user-defined function")
  11. return True
  12.  
  13.  
  14. print("Some basic types in Python:")
  15. print(type(2)) # int
  16. print(type(2.2)) # float
  17. print(type("2.2")) # str (string)
  18. print(type(2 < 2.2)) # bool (boolean)
  19. print(type(math)) # module
  20. print(type(math.tan)) # builtin_function_or_method ("function" in Brython)
  21. print(type(f)) # function (user-defined function)
  22. print(type(type(42))) # type
  23. #x is an object
  24. x = 42
  25. print(x)
  26. print(type(x))
  27. x = "hello"
  28. print(x)
  29. print(type(x))
  30. x = 5.0
  31. print(x)
  32. print(type(x))
  33.  
  34. print("Some builtin constants:")
  35. print(True)
  36. print(False)
  37. print(None)
  38.  
  39. print("And some more constants in the math module:")
  40. import math
  41. print(math.pi)
  42. print(math.e)
  43.  
  44. print("Strings:")
  45. print("hi from string one")
  46. print('hi from string two')
  47.  
  48. print("Type casting functions:")
  49. print(bool(0)) # convert to boolean (True or False)
  50. print(float(42)) # convert to a floating point number
  51. print(int(2.8)) # convert to an integer (int)
  52.  
  53.  
  54. #OPERATORS
  55. #=============================================================================
  56. #Arithmetic +, -, *, /, //, **, %
  57. #Relational <, <=, >=, >, ==, !=
  58.  
  59. print(3 * 2)
  60. print(3 * "abc")
  61. print(3 + 2)
  62. print("abc" + "def")
  63. print(3 + "def")
  64.  
  65. print("Integer division:")
  66. print(" 5/3 =", ( 5/3))
  67. print("Float division:")
  68. print(" 5.0/3 =", ( 5.0/3))
  69. print(" 5/3.0 =", ( 5/3.0))
  70.  
  71. print(" 6%3 =", ( 6%3))
  72. print(" 5%3 =", ( 5%3))
  73. print(" 2%3 =", ( 2%3))
  74. print(" 0%3 =", ( 0%3))
  75. print(" 3%0 =", ( 3%0))
  76.  
  77. print("String operators:")
  78. print("hello " + "world!")
  79. print("hello " * 3)
  80.  
  81. #PITFALLS
  82. #=============================================================================
  83. print("The problem....")
  84. d1 = 0.1 + 0.1 + 0.1
  85. d2 = 0.3
  86. print(d1 == d2) # False (never use == with floats!)
  87.  
  88.  
  89. #CLASS PROBLEMS
  90. #=============================================================================
  91. print(type("0.01"))
  92. print("hello " + 0 )
  93. print("1" + "2")
  94.  
  95. print(3/5)
  96. print(3./5)
  97.  
  98.  
  99. #*supplementary exercise* negative-mod
  100. print("-4%3 =", (-4%3))
  101. print("4%-3 =", (4%-3))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement