编写一个函数，该函数接受一个字符串作为输入，返回该字符串中所有元音字母的数量。
string = "Hello World"
下面是Python代码实现：

```python
def count_vowels(s):
    count = 0
    vowels = set('aeiouAEIOU')
    for char in s:
        if char in vowels:
            count += 1
    return count

string = "Hello World"
print(count_vowels(string)) # 输出：3
```