说说python的print
时间: 2023-11-04 16:16:12 浏览: 24
Python的`print()`函数用于将输出打印到控制台或文件中。它可以接受一个或多个参数,并将它们打印到控制台或文件中,参数之间用逗号分隔。`print()`函数默认在每个参数之间添加一个空格,并在最后一个参数后添加一个换行符。例如:
```python
print("Hello World!")
```
输出:
```
Hello World!
```
如果要在参数之间添加其他分隔符,可以使用`sep`参数。例如:
```python
print("a", "b", "c", sep="-")
```
输出:
```
a-b-c
```
如果不想在末尾添加换行符,可以使用`end`参数。例如:
```python
print("Hello", end="")
print("World!")
```
输出:
```
HelloWorld!
```
`print()`函数还支持格式化输出,可以使用`%`运算符或`format()`方法。例如:
```python
name = "Alice"
age = 30
print("My name is %s and I am %d years old." % (name, age))
# 或者
print("My name is {} and I am {} years old.".format(name, age))
```
输出:
```
My name is Alice and I am 30 years old.
```
相关问题
说说python正则表达式通配符
Python正则表达式中的通配符是指可以匹配任意字符的特殊字符,常用的通配符有以下几种:
1. ".":匹配任意一个字符,除了换行符"\n"。
2. "\w":匹配任意一个字母、数字或下划线,等价于"[a-zA-Z0-9_]"。
3. "\W":匹配任意一个非字母、数字或下划线,等价于"[^a-zA-Z0-9_]"。
4. "\d":匹配任意一个数字,等价于"[0-9]"。
5. "\D":匹配任意一个非数字,等价于"[^0-9]"。
6. "\s":匹配任意一个空白字符,包括空格、制表符、换行符等。
7. "\S":匹配任意一个非空白字符。
8. "[]":匹配方括号中任意一个字符,例如"[abc]"可以匹配"a"、"b"或"c"。
9. "[^]":匹配方括号中任意一个非字符,例如"[^abc]"可以匹配除了"a"、"b"和"c"以外的任意字符。
10. "|":匹配左右两边任意一个表达式,例如"a|b"可以匹配"a"或"b"。
下面是一个例子,演示如何使用正则表达式匹配一个字符串中的数字:
```python
import re
# 定义一个字符串
s = "hello 123 world 456"
# 使用正则表达式匹配数字
result = re.findall("\d+", s)
# 输出匹配结果
print(result) # 输出:['123', '456']
```
说说python requests模块的用法
Python requests 模块是一个用于发送 HTTP 请求的第三方库,可以用来模拟浏览器发送 GET、POST 等请求,获取网页内容或者提交表单数据等。使用 requests 模块,可以方便地实现网络爬虫、数据采集、API 接口调用等功能。常用的方法包括 requests.get()、requests.post()、requests.put()、requests.delete() 等,可以设置请求头、请求参数、请求体等参数,还可以设置代理、SSL 证书等。例如,使用 requests.get() 方法获取百度首页的代码如下:
import requests
response = requests.get('https://www.baidu.com/')
print(response.text)
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)