一天一点python03(数字和字符串1)
来源:互联网 发布:魔兽世界tcg卡牌淘宝 编辑:程序博客网 时间:2024/05/21 07:46
前两篇都是直接翻译的,以后可能会写成笔记。
1.解释器可以直接当做计算器使用:
>>> (50-5*6)/4
5.0
2.支持复数,复数的虚部可以用j或者J来表示。写成 (real+imagj),或者也可以用complex函数构造complex(real, imag)。访问实部,虚部用.real 和 .imag 来访问。
>>> 1j * 1J
(-1+0j)
>>> 1j * complex(0, 1)
(-1+0j)
>>> 3+1j*3
(3+3j)
>>> (3+1j)*3
(9+3j)
>>> (1+2j)/(1+1j)
(1.5+0.5j)
>>> a=1.5+0.5j
>>> a.real
1.5
>>> a.imag
0.5
3.字符串,字符串可以是被双引号或者单引号括起来的内容。字符串中间如果有单引号,那么整个串应该用双引号括起来。如果没有单引号,就可以用单引号。当然,转义符/也是可以用的。
>>> 'spam eggs'
'spam eggs'
>>> 'doesn/'t'
"doesn't"
>>> "doesn't"
"doesn't"
>>> '"Yes," he said.'
'"Yes," he said.'
>>> "/"Yes,/" he said."
'"Yes," he said.'
>>> '"Isn/'t," she said.'
'"Isn/'t," she said.'
超长字符串,这个跟C里面的一样。可以用/来连接。或者可以用一对 “三引号”括起来,这时,每行的'/'可以不用了。:
hello = "This is a rather long string containing/n/
several lines of text just as you would do in C./n/
Note that whitespace at the beginning of the line is/
significant."
print("""
Usage: thingy [OPTIONS]
-h Display this usage message
-H hostname Hostname to connect to
""")
我们可以把一个string当做“raw” string,也就是字符串里面是什么,打印出来就是什么:
hello = r"This is a rather long string containing/n/
several lines of text much as you would do in C."
print(hello)
结果是:
This is a rather long string containing/n/
several lines of text much as you would do in C.
- 一天一点python03(数字和字符串1)
- python03 一些简单的数字运算
- 一天一点python(FAQ-1)
- 关于ruby中求一串字符串中数字的和,小白的一点理解。
- python03-list_tuple_dict_set
- 数字,字符串 和集合
- 数字、字符串和集合
- 字符串和数字
- 字符串和数字转换
- 数字,字符串 和集合
- 数字和字符串比较
- 数字和字符串类型
- 一天一点做项目(1)
- 一天一点xib:1简单说明
- VC中数字格式化为字符串的一点心得
- 数字字符串和数字互转
- 一天一点新知识_SpringMVC中session的获取和操作
- 搞搞QT3:字符串和数字
- 行业信息化
- 在PHP中执行系统外部命令
- vs2005使用技巧
- 常用函数收集
- c# MouseClick和MouseDown的区别
- 一天一点python03(数字和字符串1)
- POJ Moving Tables
- 本周开始将进军单片机编程,立帖为证!
- 关于SmartForm和ScriptForm的输出格式设置说明
- tyjhj
- secache 缓存原理技术
- 验证dropdownlist必选
- 关于getObjectsUnderPoint
- [SQL Server] 在实例间传输用户名和密码信息