一些基础Python基础用法--采自《Python核心编程》
2017-05-24 21:36
567 查看
1.Python的print语句,与字符串格式运算符(%)结合使用,可实现字符串替换功能。
>>> print("%s is number %d!"%("Python",1))
Python is number 1!%s表示由一个字符串来替换,而%d表示由一个整数来替换。%f表示由一个浮点数来替换。
2.除号“/”“//”
>>> 12/7
1.7142857142857142
>>> 12//7
13.Python是大小写敏感的
>>> "cAsE"=="CaSe"
False
>>> "cAsE"=="cAsE"
True4.True=1,false=0
>>> c=True
>>> c+=1
>>> c
25.字符串的最后一个元素
>>> pystr='hello'
>>> pystr[-1]
'o'[:]访问字符串的子集
6.*用于字符串重复:
>>> pystr*2
'hellohello'
>>> '- '*20
'- - - - - - - - - - - - - - - - - - - - '7. 元组不可以修改
>>> aYu=('me',12,30,'love')
>>> aYu[1:3]
(12, 30)
>>> aYu[1]=11
Traceback (most recent call last):
File "<pyshell#56>", line 1, in <module>
aYu[1]=11
TypeError: 'tuple' object does not support item assignment8.字典:
>>> aDict={'host':'earth'}
>>> aDict[11]=90
>>> print("%s is number %d!"%("Python",1))
Python is number 1!%s表示由一个字符串来替换,而%d表示由一个整数来替换。%f表示由一个浮点数来替换。
>>> print("%f is a float number."%(1.345)) 1.345000 is a float number. >>> print("%s is a float number."%(1.345)) 1.345 is a float number.Python非常灵活,所以即使将数字传递给%s。也不会引发严重错误。
2.除号“/”“//”
>>> 12/7
1.7142857142857142
>>> 12//7
13.Python是大小写敏感的
>>> "cAsE"=="CaSe"
False
>>> "cAsE"=="cAsE"
True4.True=1,false=0
>>> c=True
>>> c+=1
>>> c
25.字符串的最后一个元素
>>> pystr='hello'
>>> pystr[-1]
'o'[:]访问字符串的子集
6.*用于字符串重复:
>>> pystr*2
'hellohello'
>>> '- '*20
'- - - - - - - - - - - - - - - - - - - - '7. 元组不可以修改
>>> aYu=('me',12,30,'love')
>>> aYu[1:3]
(12, 30)
>>> aYu[1]=11
Traceback (most recent call last):
File "<pyshell#56>", line 1, in <module>
aYu[1]=11
TypeError: 'tuple' object does not support item assignment8.字典:
>>> aDict={'host':'earth'}
>>> aDict[11]=90
>>> aDict.keys() dict_keys(['host', 11]) >>> aDict['host'] 'earth' >>> for key in aDict: print(key,aDict[key])
host earth 11 90
相关文章推荐
- python学习笔记(一)一些基础用法
- mod_python 的一些用法
- 正则表达式的一些用法很基础的哦
- Apache Pig的一些基础概念及用法总结
- Python的一些用法分享
- Python学习笔记《Python核心编程》第3章Python基础
- python的一些惯用法摘要
- assert 用法及获取IP 分类: python基础学习 2013-07-24 16:54 344人阅读 评论(0) 收藏
- PYTHON基础学习之操作类的一些函数
- python的一些函数用法记录
- 一些基础语句的用法
- Apache Pig的一些基础概念及用法总结(转)
- js一些基础用法
- Mysql一些基础用法
- Python基础之---运算符与用法及编码问题
- 学学python(1)一些基础知识点
- monkeyrunner其他测试例子收集,便于理解python一些基本用法
- Apache Pig的一些基础概念及用法总结3(转)
- python的一些基础知识
- python列表字典中的一些用法