python parentheses in call to print
时间: 2023-08-28 11:22:17 浏览: 122
In Python, parentheses are used in function calls to pass arguments to the `print` function as well.
The `print` function is used to display output on the console. You can pass one or more arguments to the `print` function, and they will be displayed on separate lines by default. Here's an example:
```python
print("Hello, world!")
```
In this case, the argument `"Hello, world!"` is passed to the `print` function using parentheses. When executed, it will display `Hello, world!` on the console.
You can also pass multiple arguments to the `print` function, and they will be separated by a space by default. Here's an example:
```python
name = "Alice"
age = 25
print("Name:", name, "Age:", age)
```
In this example, the `print` function is called with multiple arguments: the strings `"Name:"` and `"Age:"`, and the variables `name` and `age`. The output will be `Name: Alice Age: 25` on the console.
Additionally, you can use the `sep` parameter of the `print` function to specify a custom separator between the arguments. By default, `sep` is set to a space character. Here's an example:
```python
name = "Bob"
age = 30
print("Name:", name, "Age:", age, sep=" | ")
```
In this case, the output will be `Name: | Bob | Age: | 30`, where the separator between arguments is set to `" | "`.
Remember, when using parentheses in a function call, make sure to separate the arguments with commas and enclose them within the parentheses to pass them correctly to the `print` function.
阅读全文