# Return Statement

## return 陳述句

我們來看看以下的範例:

```python
def whichArea(area):
    if area == 'Taiwan':
        return area + '! , we are from same area.'
    else:
        return area + ', I am from Taiwan.'


print('Hi, my name is Jason. I am from Taiwan.')
print('Where are you from?')

userInput = input()
response = whichArea(userInput)

print(response)
print('Nice to meet you~')

```

函式是可以回傳值的，當我們要函式回傳值，我們必須使用`retrun`這個關鍵字。

這個範例說明著函式`whichArea(area)`回傳一個值，並將回傳的值指派給變數`response`，這樣的方式你可以重複使用變數`response`。

## None

我們來看看以下的範例:

```python
def hello1():
    print('Hello, World!')


userInput = hello1()
print(userInput)
print(type(userInput))
print(None == userInput)
print('value is ' + userInput)
```

當函式沒有`return`這個關鍵字時，回傳的值是一個`NoneType`型別的東西，值是`None`。

當我們執行以上的程式碼時，5\~8行可以正常的執行，我們可以觀察看看執行結果，來理解None是什麼東西。

而第9行，則會執行錯誤，說明著None雖然可以被印出來，但是當它與`'value is '`字串是不能直接相接的， 因為userInput是一個`NoneType`型別的值，我們必須將它轉型`str(userInput)`，我們才能將它與字串相接。

## 利用return中斷函式

我們來看看以下的範例:

```python
def helloWay(country):
    if country == 'TW':
        return '你好~'
    if country == 'US':
        return 'How are you~'
    if country == 'JP':
        return 'Konichiwa~'
    return 'Hi~'

userInput = input('您的國家是?')
print(helloWay(userInput))
```

當函式第一次遇到`return`關鍵字時，就會直接return你給定的值或是表達式，接下來的程式碼，皆不會執行。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jasonchang-ccs.gitbook.io/hello-python-tutorial/0-3/2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
