TypeError: "delimiter" must be string, not int
时间: 2023-12-18 18:04:13 浏览: 164
10种JavaScript最常见的错误(小结)
This error occurs when trying to use an integer as a delimiter instead of a string.
For example, if you're using the `split()` method to split a string into a list of substrings, you need to provide a string delimiter, such as `" "` or `","`. If you provide an integer instead, you'll get a `TypeError`.
Here's an example of code that would raise this error:
```
string = "hello world"
delimiter = 2
substrings = string.split(delimiter)
```
In this case, `delimiter` is an integer instead of a string, which causes the error. To fix it, simply use a string delimiter instead:
```
string = "hello world"
delimiter = " "
substrings = string.split(delimiter)
```
阅读全文