_请生成mytest1@163.com,123456 到mytest1000@163.com,123456的1000个邮箱账号信息,并保存在test.txt文件中,可用任意语言编辑实现。
_
with open('test.txt',mode='w') as file:for i in range(1,1001):file.write(f'test{i}@163.com,123456\n')
python 基本数据类型
字符串
定义字符串,使用 双引号"" 或者'' 引起来。
# 定义字符串a = "helloworld" # 将字符串 helloworld 赋值给变量aprint(a)
应用场景
将字符串保存的文件中。
Python中有内置函数 open() , 将helloword 写入test.txt 文件中
# 创建一个可写入权限的文件 test.txt mode 表示权限 w 写入权限with open('test.txt',mode='w') as file:# 写入内容file.write("helloworld")
特殊字符
- \n 换行 ```python a = “将字符串保存的文件中。\nPython中有内置函数 open() , 将helloword 写入test.txt 文件中”
print(a)
- r 保持原样```pythona = r"将字符串保存的文件中。\nPython中有内置函数 open() , 将helloword 写入test.txt 文件中"print(a)
数字
数字之间的加减乘除。
a = 10b = 20c = a*b*(b+a)print(c)print(a+b)print(a-b)print(a*b)print(a/b) # 除法print(10%3) # 取余数print(10//3) # 取商值print(2**3) # 2的3次方print(2**10) # 2的10次方
符号 |
||
|---|---|---|
| + | 加法 | print(1+1) |
| - | 减法 | |
| * | 乘法 | |
| ** | 次幂运算 | 2**10 2的10次方 |
| / | 除法 | |
| // | 取商 | 10//3 结果为3 |
| % | 取余数 | 10%3 结果为1 |
数字与字符串
数字n*字符串
字符串重复n次
# 打印10000行helloworlda = "\nhelloworld" * 10000print(a)
字符串+字符串
将字符串进行拼接,也就是将两个字符串合并到一起变成1个字符串。
a = "hello"b = "xiaoming"print(a+b)


作业
打印
小明字符串 100次;print("小明"*100)
使用python,写入到文件
testuser.txt文件中保存 100行小明;with open('test.txt',mode='w',encoding="utf8") as file:file.write("小明\n"*100)
- encoding 指定字符集
