Guest User

Untitled

a guest
Dec 10th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.13 KB | None | 0 0
  1. # booleans
  2. true_boolean = True
  3. false_boolean = False
  4.  
  5. # string
  6. my_name = "Leandro Tk"
  7.  
  8. # float
  9. book_price = 15.80
  10.  
  11.  
  12. if True:
  13. print("Hello Python If")
  14.  
  15. if 2 > 1:
  16. print("2 is greater than 1")
  17.  
  18.  
  19. if 1 > 2:
  20. print("1 is greater than 2")
  21. else:
  22. print("1 is not greater than 2")
  23.  
  24.  
  25.  
  26. if 1 > 2:
  27. print("1 is greater than 2")
  28. elif 2 > 1:
  29. print("1 is not greater than 2")
  30. else:
  31. print("1 is equal to 2")
  32.  
  33.  
  34. num = 1
  35.  
  36. while num <= 10:
  37. print(num)
  38. num += 1
  39.  
  40.  
  41. loop_condition = True
  42.  
  43. while loop_condition:
  44. print("Loop Condition keeps: %s" %(loop_condition))
  45. loop_condition = False
  46.  
  47.  
  48. for i in range(1, 11):
  49. print(i)
  50.  
  51. my_integers = [1, 2, 3, 4, 5]
  52.  
  53.  
  54. my_integers = [5, 7, 1, 3, 4]
  55. print(my_integers[0]) # 5
  56. print(my_integers[1]) # 7
  57. print(my_integers[4]) # 4
  58.  
  59. relatives_names = [
  60. "Toshiaki",
  61. "Juliana",
  62. "Yuji",
  63. "Bruno",
  64. "Kaio"
  65. ]
  66.  
  67. bookshelf = []
  68. bookshelf.append("The Effective Engineer")
  69. bookshelf.append("The 4 Hour Work Week")
  70. print(bookshelf[0]) # The Effective Engineer
  71. print(bookshelf[1]) # The 4 Hour Work Week
  72.  
  73.  
  74.  
  75. dictionary_example = {
  76. "key1": "value1",
  77. "key2": "value2",
  78. "key3": "value3"
  79. }
  80.  
  81.  
  82. dictionary_tk = {
  83. "name": "Leandro",
  84. "nickname": "Tk",
  85. "nationality": "Brazilian"
  86. }
  87.  
  88. print("My name is %s" %(dictionary_tk["name"])) # My name is Leandro
  89. print("But you can call me %s" %(dictionary_tk["nickname"])) # But you can call me Tk
  90. print("And by the way I'm %s" %(dictionary_tk["nationality"])) # And by the way I'm Brazilian
  91.  
  92.  
  93. dictionary_tk = {
  94. "name": "Leandro",
  95. "nickname": "Tk",
  96. "nationality": "Brazilian",
  97. "age": 24
  98. }
  99.  
  100. print("My name is %s" %(dictionary_tk["name"])) # My name is Leandro
  101. print("But you can call me %s" %(dictionary_tk["nickname"])) # But you can call me Tk
  102. print("And by the way I'm %i and %s" %(dictionary_tk["age"], dictionary_tk["nationality"])) # And by the way I'm Brazilian
  103.  
  104.  
  105. dictionary_tk = {
  106. "name": "Leandro",
  107. "nickname": "Tk",
  108. "nationality": "Brazilian"
  109. }
  110.  
  111. dictionary_tk['age'] = 24
  112.  
  113. print(dictionary_tk) # {'nationality': 'Brazilian', 'age': 24, 'nickname': 'Tk', 'name': 'Leandro'}
  114.  
  115.  
  116.  
  117. bookshelf = [
  118. "The Effective Engineer",
  119. "The 4 hours work week",
  120. "Zero to One",
  121. "Lean Startup",
  122. "Hooked"
  123. ]
  124.  
  125. for book in bookshelf:
  126. print(book)
  127.  
  128.  
  129. dictionary = { "some_key": "some_value" }
  130.  
  131. for key in dictionary:
  132. print("%s --> %s" %(key, dictionary[key]))
  133.  
  134. # some_key --> some_value
  135.  
  136. dictionary = { "some_key": "some_value" }
  137.  
  138. for key, value in dictionary.items():
  139. print("%s --> %s" %(key, value))
  140.  
  141. # some_key --> some_value
  142.  
  143.  
  144. dictionary_tk = {
  145. "name": "Leandro",
  146. "nickname": "Tk",
  147. "nationality": "Brazilian",
  148. "age": 24
  149. }
  150.  
  151. for attribute, value in dictionary_tk.items():
  152. print("My %s is %s" %(attribute, value))
  153.  
  154. # My name is Leandro
  155. # My nickname is Tk
  156. # My nationality is Brazilian
  157. # My age is 24
  158.  
  159.  
  160. class Vehicle:
  161. pass
  162.  
  163. car = Vehicle()
  164. print(car) # <__main__.Vehicle instance at 0x7fb1de6c2638>
  165.  
  166. class Vehicle:
  167. def __init__(self, number_of_wheels, type_of_tank, seating_capacity, maximum_velocity):
  168. self.number_of_wheels = number_of_wheels
  169. self.type_of_tank = type_of_tank
  170. self.seating_capacity = seating_capacity
  171. self.maximum_velocity = maximum_velocity
  172.  
  173. tesla_model_s = Vehicle(4, 'electric', 5, 250)
  174.  
  175.  
  176. class Vehicle:
  177. def __init__(self, number_of_wheels, type_of_tank, seating_capacity, maximum_velocity):
  178. self.number_of_wheels = number_of_wheels
  179. self.type_of_tank = type_of_tank
  180. self.seating_capacity = seating_capacity
  181. self.maximum_velocity = maximum_velocity
  182.  
  183. def number_of_wheels(self):
  184. return self.number_of_wheels
  185.  
  186. def set_number_of_wheels(self, number):
  187. self.number_of_wheels = number
  188.  
  189. class Vehicle:
  190. def __init__(self, number_of_wheels, type_of_tank, seating_capacity, maximum_velocity):
  191. self.number_of_wheels = number_of_wheels
  192. self.type_of_tank = type_of_tank
  193. self.seating_capacity = seating_capacity
  194. self.maximum_velocity = maximum_velocity
  195.  
  196. @property
  197. def number_of_wheels(self):
  198. return self.number_of_wheels
  199.  
  200. @number_of_wheels.setter
  201. def number_of_wheels(self, number):
  202. self.number_of_wheels = number
  203.  
  204. tesla_model_s = Vehicle(4, 'electric', 5, 250)
  205. print(tesla_model_s.number_of_wheels) # 4
  206. tesla_model_s.number_of_wheels = 2 # setting number of wheels to 2
  207. print(tesla_model_s.number_of_wheels) # 2
  208.  
  209.  
  210. class Vehicle:
  211. def __init__(self, number_of_wheels, type_of_tank, seating_capacity, maximum_velocity):
  212. self.number_of_wheels = number_of_wheels
  213. self.type_of_tank = type_of_tank
  214. self.seating_capacity = seating_capacity
  215. self.maximum_velocity = maximum_velocity
  216.  
  217. def make_noise(self):
  218. print('VRUUUUUUUM')
  219.  
  220. tesla_model_s = Vehicle(4, 'electric', 5, 250)
  221. tesla_model_s.make_noise() # VRUUUUUUUM
  222.  
  223.  
  224. class Person:
  225. def __init__(self, first_name):
  226. self.first_name = first_name
  227.  
  228. tk = Person('TK')
  229. print(tk.first_name) # => TK
  230.  
  231.  
  232. class Person:
  233. first_name = 'TK'
  234.  
  235. tk = Person()
  236. print(tk.first_name) # => TK
  237.  
  238.  
  239. tk = Person('TK')
  240. tk.first_name = 'Kaio'
  241. print(tk.first_name) # => Kaio
  242.  
  243. class Person:
  244. def __init__(self, first_name, email):
  245. self.first_name = first_name
  246. self._email = email
  247.  
  248.  
  249. tk = Person('TK', 'tk@mail.com')
  250. print(tk._email) # tk@mail.com
  251.  
  252.  
  253. class Person:
  254. def __init__(self, first_name, email):
  255. self.first_name = first_name
  256. self._email = email
  257.  
  258. def update_email(self, new_email):
  259. self._email = new_email
  260.  
  261. def email(self):
  262. return self._email
  263.  
  264.  
  265. tk = Person('TK', 'tk@mail.com')
  266. print(tk.email()) # => tk@mail.com
  267. tk._email = 'new_tk@mail.com'
  268. print(tk.email()) # => tk@mail.com
  269. tk.update_email('new_tk@mail.com')
  270. print(tk.email()) # => new_tk@mail.com
  271.  
  272.  
  273. class Person:
  274. def __init__(self, first_name, age):
  275. self.first_name = first_name
  276. self._age = age
  277.  
  278. def show_age(self):
  279. return self._age
  280.  
  281. tk = Person('TK', 25)
  282. print(tk.show_age()) # => 25
  283.  
  284.  
  285. class Person:
  286. def __init__(self, first_name, age):
  287. self.first_name = first_name
  288. self._age = age
  289.  
  290. def _show_age(self):
  291. return self._age
  292.  
  293. tk = Person('TK', 25)
  294. print(tk._show_age()) # => 25
  295.  
  296.  
  297.  
  298. class Person:
  299. def __init__(self, first_name, age):
  300. self.first_name = first_name
  301. self._age = age
  302.  
  303. def show_age(self):
  304. return self._get_age()
  305.  
  306. def _get_age(self):
  307. return self._age
  308.  
  309. tk = Person('TK', 25)
  310. print(tk.show_age()) # => 25
  311.  
  312.  
  313. class Car:
  314. def __init__(self, number_of_wheels, seating_capacity, maximum_velocity):
  315. self.number_of_wheels = number_of_wheels
  316. self.seating_capacity = seating_capacity
  317. self.maximum_velocity = maximum_velocity
  318.  
  319. my_car = Car(4, 5, 250)
  320. print(my_car.number_of_wheels)
  321. print(my_car.seating_capacity)
  322. print(my_car.maximum_velocity)
  323.  
  324.  
  325. class ElectricCar(Car):
  326. def __init__(self, number_of_wheels, seating_capacity, maximum_velocity):
  327. Car.__init__(self, number_of_wheels, seating_capacity, maximum_velocity)
  328.  
  329.  
  330. my_electric_car = ElectricCar(4, 5, 250)
  331. print(my_electric_car.number_of_wheels) # => 4
  332. print(my_electric_car.seating_capacity) # => 5
  333. print(my_electric_car.maximum_velocity) # => 250
Add Comment
Please, Sign In to add comment