Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # booleans
- true_boolean = True
- false_boolean = False
- # string
- my_name = "Leandro Tk"
- # float
- book_price = 15.80
- if True:
- print("Hello Python If")
- if 2 > 1:
- print("2 is greater than 1")
- if 1 > 2:
- print("1 is greater than 2")
- else:
- print("1 is not greater than 2")
- if 1 > 2:
- print("1 is greater than 2")
- elif 2 > 1:
- print("1 is not greater than 2")
- else:
- print("1 is equal to 2")
- num = 1
- while num <= 10:
- print(num)
- num += 1
- loop_condition = True
- while loop_condition:
- print("Loop Condition keeps: %s" %(loop_condition))
- loop_condition = False
- for i in range(1, 11):
- print(i)
- my_integers = [1, 2, 3, 4, 5]
- my_integers = [5, 7, 1, 3, 4]
- print(my_integers[0]) # 5
- print(my_integers[1]) # 7
- print(my_integers[4]) # 4
- relatives_names = [
- "Toshiaki",
- "Juliana",
- "Yuji",
- "Bruno",
- "Kaio"
- ]
- bookshelf = []
- bookshelf.append("The Effective Engineer")
- bookshelf.append("The 4 Hour Work Week")
- print(bookshelf[0]) # The Effective Engineer
- print(bookshelf[1]) # The 4 Hour Work Week
- dictionary_example = {
- "key1": "value1",
- "key2": "value2",
- "key3": "value3"
- }
- dictionary_tk = {
- "name": "Leandro",
- "nickname": "Tk",
- "nationality": "Brazilian"
- }
- print("My name is %s" %(dictionary_tk["name"])) # My name is Leandro
- print("But you can call me %s" %(dictionary_tk["nickname"])) # But you can call me Tk
- print("And by the way I'm %s" %(dictionary_tk["nationality"])) # And by the way I'm Brazilian
- dictionary_tk = {
- "name": "Leandro",
- "nickname": "Tk",
- "nationality": "Brazilian",
- "age": 24
- }
- print("My name is %s" %(dictionary_tk["name"])) # My name is Leandro
- print("But you can call me %s" %(dictionary_tk["nickname"])) # But you can call me Tk
- print("And by the way I'm %i and %s" %(dictionary_tk["age"], dictionary_tk["nationality"])) # And by the way I'm Brazilian
- dictionary_tk = {
- "name": "Leandro",
- "nickname": "Tk",
- "nationality": "Brazilian"
- }
- dictionary_tk['age'] = 24
- print(dictionary_tk) # {'nationality': 'Brazilian', 'age': 24, 'nickname': 'Tk', 'name': 'Leandro'}
- bookshelf = [
- "The Effective Engineer",
- "The 4 hours work week",
- "Zero to One",
- "Lean Startup",
- "Hooked"
- ]
- for book in bookshelf:
- print(book)
- dictionary = { "some_key": "some_value" }
- for key in dictionary:
- print("%s --> %s" %(key, dictionary[key]))
- # some_key --> some_value
- dictionary = { "some_key": "some_value" }
- for key, value in dictionary.items():
- print("%s --> %s" %(key, value))
- # some_key --> some_value
- dictionary_tk = {
- "name": "Leandro",
- "nickname": "Tk",
- "nationality": "Brazilian",
- "age": 24
- }
- for attribute, value in dictionary_tk.items():
- print("My %s is %s" %(attribute, value))
- # My name is Leandro
- # My nickname is Tk
- # My nationality is Brazilian
- # My age is 24
- class Vehicle:
- pass
- car = Vehicle()
- print(car) # <__main__.Vehicle instance at 0x7fb1de6c2638>
- class Vehicle:
- def __init__(self, number_of_wheels, type_of_tank, seating_capacity, maximum_velocity):
- self.number_of_wheels = number_of_wheels
- self.type_of_tank = type_of_tank
- self.seating_capacity = seating_capacity
- self.maximum_velocity = maximum_velocity
- tesla_model_s = Vehicle(4, 'electric', 5, 250)
- class Vehicle:
- def __init__(self, number_of_wheels, type_of_tank, seating_capacity, maximum_velocity):
- self.number_of_wheels = number_of_wheels
- self.type_of_tank = type_of_tank
- self.seating_capacity = seating_capacity
- self.maximum_velocity = maximum_velocity
- def number_of_wheels(self):
- return self.number_of_wheels
- def set_number_of_wheels(self, number):
- self.number_of_wheels = number
- class Vehicle:
- def __init__(self, number_of_wheels, type_of_tank, seating_capacity, maximum_velocity):
- self.number_of_wheels = number_of_wheels
- self.type_of_tank = type_of_tank
- self.seating_capacity = seating_capacity
- self.maximum_velocity = maximum_velocity
- @property
- def number_of_wheels(self):
- return self.number_of_wheels
- @number_of_wheels.setter
- def number_of_wheels(self, number):
- self.number_of_wheels = number
- tesla_model_s = Vehicle(4, 'electric', 5, 250)
- print(tesla_model_s.number_of_wheels) # 4
- tesla_model_s.number_of_wheels = 2 # setting number of wheels to 2
- print(tesla_model_s.number_of_wheels) # 2
- class Vehicle:
- def __init__(self, number_of_wheels, type_of_tank, seating_capacity, maximum_velocity):
- self.number_of_wheels = number_of_wheels
- self.type_of_tank = type_of_tank
- self.seating_capacity = seating_capacity
- self.maximum_velocity = maximum_velocity
- def make_noise(self):
- print('VRUUUUUUUM')
- tesla_model_s = Vehicle(4, 'electric', 5, 250)
- tesla_model_s.make_noise() # VRUUUUUUUM
- class Person:
- def __init__(self, first_name):
- self.first_name = first_name
- tk = Person('TK')
- print(tk.first_name) # => TK
- class Person:
- first_name = 'TK'
- tk = Person()
- print(tk.first_name) # => TK
- tk = Person('TK')
- tk.first_name = 'Kaio'
- print(tk.first_name) # => Kaio
- class Person:
- def __init__(self, first_name, email):
- self.first_name = first_name
- self._email = email
- tk = Person('TK', 'tk@mail.com')
- print(tk._email) # tk@mail.com
- class Person:
- def __init__(self, first_name, email):
- self.first_name = first_name
- self._email = email
- def update_email(self, new_email):
- self._email = new_email
- def email(self):
- return self._email
- tk = Person('TK', 'tk@mail.com')
- print(tk.email()) # => tk@mail.com
- tk._email = 'new_tk@mail.com'
- print(tk.email()) # => tk@mail.com
- tk.update_email('new_tk@mail.com')
- print(tk.email()) # => new_tk@mail.com
- class Person:
- def __init__(self, first_name, age):
- self.first_name = first_name
- self._age = age
- def show_age(self):
- return self._age
- tk = Person('TK', 25)
- print(tk.show_age()) # => 25
- class Person:
- def __init__(self, first_name, age):
- self.first_name = first_name
- self._age = age
- def _show_age(self):
- return self._age
- tk = Person('TK', 25)
- print(tk._show_age()) # => 25
- class Person:
- def __init__(self, first_name, age):
- self.first_name = first_name
- self._age = age
- def show_age(self):
- return self._get_age()
- def _get_age(self):
- return self._age
- tk = Person('TK', 25)
- print(tk.show_age()) # => 25
- class Car:
- def __init__(self, number_of_wheels, seating_capacity, maximum_velocity):
- self.number_of_wheels = number_of_wheels
- self.seating_capacity = seating_capacity
- self.maximum_velocity = maximum_velocity
- my_car = Car(4, 5, 250)
- print(my_car.number_of_wheels)
- print(my_car.seating_capacity)
- print(my_car.maximum_velocity)
- class ElectricCar(Car):
- def __init__(self, number_of_wheels, seating_capacity, maximum_velocity):
- Car.__init__(self, number_of_wheels, seating_capacity, maximum_velocity)
- my_electric_car = ElectricCar(4, 5, 250)
- print(my_electric_car.number_of_wheels) # => 4
- print(my_electric_car.seating_capacity) # => 5
- print(my_electric_car.maximum_velocity) # => 250
Add Comment
Please, Sign In to add comment