View on GitHub

Python-Tutorial

https://github.com/kdheepak/Python-Tutorial

Functions

Functions

print("hello world")
print
type(print)
sleep
type(sleep)
def function_name():
    print("hello world")
function_name
type(function_name)
function_name()
def add_two_numbers(x, y):
    print(x + y)
add_two_numbers(1, 2)
z = add_two_numbers(1, 2)
z
z == None
def add_two_numbers_and_return_result(x, y):
    print(x + y)
    return x + y
add_two_numbers_and_return_result(1, 2)
z = add_two_numbers_and_return_result(1, 2)
z
def add_two_strings_with_a_space(s1, s2):

    return s1 + " " + s2
add_two_strings_with_a_space("hello", "world")
add_two_strings_with_a_space(s1="hello", s2="world")
s1
add_two_strings_with_a_space(s3="hello", s2="world")
add_two_strings_with_a_space(s2="world", s1="hello")
def add_two_strings(s1, s2, delimiter=" "):

    return s1 + delimiter + s2
add_two_strings("hello", "world")
add_two_strings("hello", "world", "_______")
add_two_strings("hello", "world", delimiter="_______")

Scopes

def function():
    my_name_inside_function = "John Doe"
    print(my_name_inside_function)
function()
my_name_inside_function
age = 100
def function():
    print(age)
function()