栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python笔记

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python笔记

1、字符串
str='Hello World!'
1)取值print str[0],得到:H
2)分割str.split('o'),得到:['Hell', ' w', 'rd']

2、列表List
list=['qq',''ww',''ee']
1)追加list.append('rr'),得到:['qq', 'ww', 'ee', 'rr']
2)删除del list[1],得到:['qq', 'ee', 'rr']
3)个数len(list)
4)反转list.reverse()

3、字典Dictionary
dict={'name':'mangmang','age':24}
1)取值print dict['age'],得到:24
2)修改dict['age']=25,得到:25
3)删除del dict['age'],得到:{'name': 'mangmang'}

4、For循环
1)字符串循环

for word in 'Hello world!':
    print word

2)循环List

//第一种
list是=['qq', 'ww', 'ee', 'rr']
for list in lists:
    print list
//第二种通过序列索引迭代
//range取值范围是0~3
for num in range(len(lists):
    print lists[num]

5、数据库连接
1)使用流程
-引入 API 模块。
-获取与数据库的连接。
-执行SQL语句和存储过程。
-关闭数据库连接。
2)连接数据库
db = MySQLdb.connect("localhost","testuser","test123","库名称" )
3)获取操作游标/切换库操作
cursor = db.cursor()
cursor.select_db('database name')
4)执行sql语句
cursor.execute("SELECT VERSION()")
5)获取数据
data = cursor.fetchone()
6)关闭数据库
db.close()
7)提交事务,除查询外的操作使用
db.commit()
8)获取所有数据
cursor.fetchall()
9)返回执行execute()方法后影响的行数
cursor.rowcount()

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/224893.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号