09. Check For Understanding: Variable Scope

Check for Understanding

In the below questions, you will get some practice working with variable scope. It is important to understand variable scope, as this often can lead to confusion when writing code that solves complex problems.

Use the code below to determine what will print to the console.
```
str1 = 'Functions are important programming concepts.'

def print_fn():
str1 = 'Variable scope is an important concept.'
print(str1)

print_fn()```

What will happen when we run this code?

SOLUTION: It will print 'Variable scope is an important concept.'

Now let's say we tweak the code a bit and comment out str1 = 'Variable scope is an important concept.'
```
str1 = 'Functions are important programming concepts.'

def print_fn():
#str1 = 'Variable scope is an important concept.'
print(str1)

print_fn()```

What will happen when we run this code?

SOLUTION: It will print 'Functions are an important programming concept.'

We made another tweak to the code.
```
def print_fn():
str1 = 'Variable scope is an important concept.'
print(str1)

print_fn(str1)```

What do you think will happen when we run this code?

SOLUTION: It will give a TypeError: print_fn() takes 0 positional arguments but 1 was given

We made a final tweak to the code.
```
str1 = 'Functions are important programming concepts.'

def print_fn():
print(str1)

print_fn(str1)```

Now what do you think will happen?

SOLUTION: It still gives a TypeError: print_fn() takes 0 positional arguments but 1 was given

Start Quiz:

## Please use this space to test and run your code