In [1]:
a = int(input())
b = int(input())
In [2]:
print (a+b)
In [3]:
import gc
del a
del b
gc.collect()
Out[3]:
In [4]:
def add_function(a,b):
print ('Calculating the sum of: ' + str(a) + " , " + str(b))
return (a+b)
In [5]:
input_1 = int(input())
input_2 = int(input())
In [6]:
result = add_function(input_1, input_2)
In [7]:
print (result)
In [8]:
import gc
del input_1
del input_2
del result
gc.collect()
Out[8]:
In [9]:
def add_function(input_1=None, input_2=None):
if input_1 and input_2 !=None:
print ('Calculating the sum of: ' + str(input_1) + " , " + str(input_2))
return (a+b)
else:
print ('Nothing to do here ...')
print ('Ensure add_function passes two keyword variables: input_1 and input_2 ...')
In [10]:
a = float(input())
b = float(input())
In [11]:
result = add_function(input_2=b, input_1=a)
In [12]:
print (result)
In [13]:
result = add_function(input_1=a)
Python is an “object-oriented programming language.” This means almost all the code is implemented using a special construct called classes. Programmers use classes to keep related things together. This is done using the keyword “class,” which is a grouping of object-oriented constructs.
In [14]:
class some_class:
some_variable = "Some string inside python class."
def some_function(self):
return ("This is a message inside the class.")
In [15]:
some_object = some_class()
In [16]:
print(some_class.some_variable)
In [17]:
print(some_object.some_variable)
In [18]:
some_object.some_variable = 'This is the modified variable.'
In [19]:
print (some_object.some_variable)
In [20]:
print(some_object.some_function())
In [21]:
first_object = some_class()
second_object = some_class()
In [22]:
second_object.some_variable = "Modified variable string for some_class."
In [23]:
print(first_object.some_variable)
print(second_object.some_variable)
In [24]:
print(first_object.some_function())
In [25]:
class Dog:
kind = 'I am a dog. According to scientists, I belong to a species called Canis lupus, under the sub-species familiaris.'
def __init__(self, name = None, type = None):
self.name = name
self.type = type
def dog_color(self, color = None):
if color and self.name and self.type != None:
color = color.lower()
if color == ('pink'):
print ("Your dog " + str(self.name) + "'s " + color + " color is so cute ...")
elif color == ('blue'):
print ("Your dog " + str(self.name) + "'s " + color + " color makes it look like a smurf ...")
else:
print ("Your dog: " + str(self.name) + "'s " + "color is: " + color + ".")
else:
print ("Nothing to do here ...")
def my_dog(self):
if self.name and self.type != None:
print ("Your dog " + str(self.name) + " is: " + str(self.type))
else:
print ("Nothing to do here ...")
In [26]:
my_dog = Dog()
In [27]:
my_dog.name = 'Puppy'
In [28]:
my_dog.type = 'Maltese'
In [29]:
print(my_dog)
In [30]:
print(my_dog.name)
In [31]:
print(my_dog.kind)
In [32]:
print(my_dog.type)
In [33]:
my_dog = Dog(name = 'Puppy', type = 'Maltese')
In [34]:
my_dog.my_dog()
In [35]:
my_dog.hello_world = "Hello World"
In [36]:
my_dog.hello_world
Out[36]:
In [37]:
my_dog.dog_color(color = 'Pink')
In [38]:
my_dog.dog_color(color='Blue')
In [39]:
my_dog.name = "Cute Puppy"
In [40]:
my_dog.my_dog()
In [41]:
my_dog.dog_color(color='Black')