python中end的各种用法举例说明
时间: 2024-04-29 12:22:37 浏览: 90
python中append实例用法总结
Sure! Here are some examples of using "end" in Python:
1. By default, the "print" function in Python ends with a newline character. However, you can use the "end" parameter to specify a different character to use instead. For example:
```
print("Hello", end="!!!")
```
This would print "Hello!!!" (with three exclamation marks at the end) instead of "Hello\n".
2. You can also use "end" to suppress the default newline character altogether. For example:
```
print("Hello", end="")
```
This would print "Hello" without any newline character.
3. You can use "end" to concatenate strings instead of using the "+" operator. For example:
```
print("Hello", "world", end="!")
```
This would print "Hello world!" (with a single space between "Hello" and "world") instead of "Hello" and "world" on separate lines.
Hope that helps! Let me know if you have any other questions.
阅读全文