Create your own Python code examples that demonstrate each of the following. Do not copy examples from the book or any other source. Try to be creative with your examples to demonstrate that you invented them yourself.
"""
example 1
example(test_value)
test_value its local variable
test_value -this is a function parameter
example(5)
5 -this is the function argument
"""
def example(test_value):
print(test_value*5)
example(5)
"""
example 2
example(12) -function call as argument value
example(variable) -function call as argument variable
example('test'[2]) -function call as argument expression
"""
variable = 4
def example(test_value):
print(test_value*5)
example(12)
example(variable)
example('test'[2])
"""
example 3
local_variable is a scoped local variable щтдн within a function
print(local_variable) - will cause an error because the scope
of the variable is not available
print(local_variable) -NameError: name 'local_variable' is not defined
"""
def example(test_value):
local_variable =5
print(test_value*local_variable)
print(local_variable)
"""
example 4
When using a variable name outside of a function,
a global variable with its own scope and value will be created
uniq_name = "global"
print(uniq_name)
result value global vasriable:
will be displayed:
global
example('local') - working with a local variable uniq_name
will be displayed:
locallocal
"""
def example(uniq_name):
uniq_name = 2*uniq_name
print(uniq_name)
uniq_name = "global"
print(uniq_name)
example('local') - working with a local variable
Comments
nice work
Leave a comment