Python中列表、元组、占位符的用法
2016-02-19 11:39
686 查看
占位符
>>> a='yang' >>> b='shixian' >>> welcome='Hello,%s %s' >>> print(welcome % (a,b)) Hello,yang shixian >>> spaces=' '*25 >>> print(spaces) >>> print('%s subject' % spaces) subject >>>
列表
列表中添加元素用append(value)、删除用remove(value)或者 del listaa[1]>>> list3 = [1,2,3,'ab'] >>> print(list3) [1, 2, 3, 'ab'] >>> list3.remove('ab') >>> print(list3) [1, 2, 3] >>> list1.remove(p4)
元组
# 这里是键值关系对 >>> list2={'1':'a','2':'b','3':'c','4':'d','5':'e'} # 显示键1对应的值 >>> print(list2['1']) a >>> print(list2) {'3': 'c', '1': 'a', '5': 'e', '2': 'b', '4': 'd'} >>> print(list2) {'3': 'c', '1': 'a', '5': 'e', '2': 'b', '4': 'd'} # 删除键值>>> del list2['5'] >>> print(list2) {'3': 'c', '1': 'a', '2': 'b', '4': 'd'}
字符串中,如何显示变量
>>> age=25 >>> if age>20: print('You are %s years old !' % age) You are 25 years old ! >>>
相关文章推荐
- 使用python爬取csdn博客访问量
- 在Mac OS 10.11上安装python, pyqt
- python实现KNN的一些问题
- 读书笔记 -《Python 黑帽子》 ( 四 )
- 本·拉登的书架:Python文本分析拉登最常念叨什么?
- 使用pycharm搭建python开发环境及连接greenplum和mysql
- python2.7.11 win32位无法卸载
- python网页爬虫之列车时刻表的抓取-完整的python脚本
- Python实现以时间换空间的缓存替换算法
- Python IDLE 清屏
- Python使用爬虫猜密码
- Python处理JSON数据
- Python笔记(3)——控制语句和函数
- Python主文件路径和当前模块路径
- Python文件操作
- python-整理-vs2013新建文件编码
- Python学习笔记day5
- Python中的swap函数
- Python使用爬虫猜密码
- Python实现以时间换空间的缓存替换算法