Popular Posts

Wednesday, August 26, 2020

Python Beginner: Return Statements

 Hello, Python developer!


I hope you have good ideas to utilize functions on your Python programming. 


Today, we will learn the "Return Statements". When you input values into functions through "parameters" and if you want to get calculated values from functions, you can use "Return" command for returning values from function.


Here is definition and example of return command.


Return command example

return function_value # return command should be in the function


I showed full exercise codes and execution result as following.

def cube(num):
num*num*num # There is no return value
print(cube(3))

def cube2(num):
return num * num * num
print(cube2(3))

def cube3(num):
a = num * num * num + 10
b = a * 2
return b

result = cube3(4)
print(result)


Can you see same result? Great! Now you can input and output values in the function.

See you on next post! 




Python Beginner: Functions

 Hello, developer!


Today, we will learn the Functions. A function is a group of codes execute for purpose. You already used some functions previous posts using import command. You can divide your whole program codes into some parts as functions and you can effectively manage your program development cycle better. Function is one of import concept in programming so we wish you learn it as clearly.


Let's start to make function with following command.


Function definition and coding example

def function_name():

       print("This is my first Python function!") # In function code(This line is indented)


"def" is function definition command and next lines are automatically indented. If your codes are not indented, it should not be in function.


If you want to input any value in function, you can use "parameter" to input the value in the function as below codes.


def my_friend(name, age): # "name", "age" are parameters, we can input values in the function through parameters 

       print("Hello " + name + ", you are " + str(age)) # In function code(This line is indented)


my_friend("Mike", 35) # Out of function code(This line is not indented, "my_friend" function execution code)  

my_friend("Steve", 70) # Out of function code(This line is not indented, "my_friend" function execution code) 


I showed full exercise codes as following and execution result.

def function_name():
print("This is my first Python function!") # In function code(This line is indented)

print("Top")
function_name()
print("Bottom")


def my_friend(name, age): # "name", "age" are parameters, we can input values in the function through parameters
print("Hello " + name + ", you are " + str(age)) # In function code(This line is indented)

my_friend("Mike", 35) # Out of function code(This line is not indented, "my_friend" function execution code)
my_friend("Steve", 70) # Out of function code(This line is not indented, "my_friend" function execution code)


Can you see the same result? Congratulations! Now you are developer who can use function.

I recommend you how can you utilize this function as well.


Thank you and see you on next post! 😊








Tuesday, August 25, 2020

Python Beginner: Tuples

 Hello, developer!


Today, we will learn the Tuples. A tuple is a set of unchangeable data. It is similar with lists but we can't modify item in the tuple. A tuple declared with ( ). I showed some examples of tuples as following.


Tuple examples

- Mathematical constants (3.141592, 2.718)  

- Root constants (1, 1.414, 1.732, 2, 2.236) 

- Product prices ( 5, 10, 15, 30, 50, 100)


If you tried to modify value in the tuples, Python shows you an error. But you can modify the value in the list as following codes exercise.

coordinates = (4, 5)
coordinates2 = [(4,5), (6,7), (80,34)]
coordinates2[1] = 10
print(coordinates)
print(coordinates2)

Can you understand the difference between tuples and lists? Simply we can say a tuple is unchangeable data set and a list is changeable data set. We can utilize tuples in the fixed values - constants in math, science or measurements in the world like height, distance, length or product prices, etc.


Are you clear on tuples? Great! Congratulations, developer!

See you on next post! 😊





Python - Web crawling exercises

Hello Python developer! How are you? Hope you've been good and had wonderful time with Python. There are 10 Python requests module exerc...