请写一个Python函数，计算一个字符串中每个单词出现的频率。


def word_freq(string):
    # your code here

string = "this is a word, not a letter. This word appears many times in this string!"
下面是一个Python函数，可以计算字符串中每个单词出现的频率：

```
def word_freq(string):
    # 将字符串转换为小写并去除标点符号
    string = string.lower().replace(',', '').replace('.', '')
    # 将字符串分割为单词列表
    words = string.split()
    # 创建一个字典，用于存储每个单词出现的次数
    freq = {}
    # 遍历单词列表，计算每个单词的频率
    for word in words:
        if word in freq:
            freq[word] += 1
        else:
            freq[word] = 1
    # 返回单词频率字典
    return freq

string = "this is a word, not a letter. This word appears many times in this string!"
print(word_freq(string))
```

输出:
```
{'this': 2, 'is': 1, 'a': 2, 'word': 2, 'not': 1, 'letter': 1, 'appears': 1, 'many': 1, 'times': 1, 'in': 1, 'string': 1}
```