摘要: 01 环境检测: from selenium import webdriver import time d = webdriver.Chrome() # 打开谷歌浏览器 d.get('https://www.baidu.com') # get() 在当前窗口打开网址 time.sleep(3) # 阅读全文
posted @ 2022-03-23 22:47 ls珊 阅读(107) 评论(0) 推荐(0) 编辑
摘要: 想使用 calc.py 中的 add ,sub 函数 from calc import add,sub # 从 calc 中,导入 add 和 sub 只有导入了函数,后面才能使用这个函数 默认情况下,只能够导入同级目录文件 阅读全文
posted @ 2022-03-05 23:41 ls珊 阅读(21) 评论(0) 推荐(0) 编辑
摘要: 建立数据库连接 import pymysql db = pymysql.connect(host='1.12.220.6',port=3306,user='tester',password='tester123',database='sqldb',charset='utf8') # 连接数据库 # 阅读全文
posted @ 2022-03-05 23:36 ls珊 阅读(146) 评论(0) 推荐(0) 编辑
摘要: hashlib 模块: 加密模块:MD5,SHA1,SHA224,SHA256,SHA384,SHA512(固定的) md5加密 方式 import hashlib m = hashlib.md5() m.update('test123'.encode(encoding='utf-8')) msg 阅读全文
posted @ 2022-03-05 23:26 ls珊 阅读(29) 评论(0) 推荐(0) 编辑
摘要: 加法的函数 def add(x,y): print(x+y) 减法的函数 def sub(x,y): print(x-y) 如果你的代码,在日后有可能被别人所调用,注意不要在代码中有执行的动作。 阅读全文
posted @ 2022-03-05 22:28 ls珊 阅读(22) 评论(0) 推荐(0) 编辑
摘要: 拆包 函数:用这个表示 data 1. def add(num1,num2,num3,num4): print(num1+num2+num3+num4) data = [3,5,7,8] add(data[0],data[1],data[2],data[3]) 2.在 data前面加上一个*,表示拆 阅读全文
posted @ 2022-03-03 23:25 ls珊 阅读(218) 评论(0) 推荐(0) 编辑
摘要: 在函数内部 定义的变量(局部变量),只针对函数生效,如果在函数的外部去使用,则会报错 def hello(): age = 18 # 在函数内部 定义的变量(局部变量),只针对函数生效,如果在函数的外部去使用,则会报错 print(age) 全局变量,针对当前这个脚本 都生效 address = ' 阅读全文
posted @ 2022-03-03 23:19 ls珊 阅读(39) 评论(0) 推荐(0) 编辑
摘要: 函数 语句: def 函数的名称(): 函数具体要执行的代码 函数具体要执行的代码 通过 def 关键字 ,可以创建函数 def sayhello(): print('这是我创建的第一个函数') print('随便打印一些内容') 函数并不会自动执行,函数一定是需要调用才执行的 通过 函数名() 的 阅读全文
posted @ 2022-03-03 23:04 ls珊 阅读(39) 评论(0) 推荐(0) 编辑
摘要: 报错 / 异常 语句: try: 检测是否会错误信息 except: 如果出错了,则执行的内容 当try语句中的代码,出错了,就会立刻跳转执行 except语句的内容 try: print('hello') int('a') # 当try语句中的代码,出错了,就会立刻跳转执行 except语句的内容 阅读全文
posted @ 2022-03-03 23:00 ls珊 阅读(16) 评论(0) 推荐(0) 编辑
摘要: 切片用 中括号,里面加个冒号表示: [:] 用切片打印出元素 a = 'adfhadfhdf' print(a[3:9:2]) # hadfhd hdh 切片 [开始:结束] 顾头不顾尾 print(a[2:7]) # 从下标为2的开始,读取到下标为7的结束,不包括下标为7的元素 print(a[: 阅读全文
posted @ 2022-03-02 23:04 ls珊 阅读(142) 评论(0) 推荐(0) 编辑