Python基础教程---读书笔记一

1. 除法运算:整数相除,结果只留整数,除非python

1)用浮点数ide

2)明确python除法执行方式:from __future__ import division函数

>>> 1/2spa

0code


2. 整除运算(include float)://字符串

>>> 5.0//2input

2.0it


3. 取余运算(including float): %io

>>> 2.75%0.5ast

0.25


4. 幂运算(include float): **

>>> (-2.0)**2

4.0


5. 长整型数:L


6. 变量不能以数字开头,使用以前赋值


7. 单引号字符串和转义引号:

>>> "Let's go!"

"Let's go!"

>>> 'lets go!'

'lets go!'

>>> 'Let\'s say \"hello world!\"'

'Let\'s say "hello world!"'


8. 字符串拼接:+, 字符串和数字不能够直接拼接

>>> print "tmp is " + tmp

Traceback (most recent call last):

 File "<stdin>", line 1, in <module>

TypeError: cannot concatenate 'str' and 'int' objects

>>> print "tmp is %d" % tmp

tmp is 2

>>> print "tmp is " + str(tmp)

tmp is 2


9. 长字符串使用三个单引号或者三个双引号,中间能够包含单引号和双引号


10. 原始字符串:以r开头,最后一个字符不能是反斜线,除非进行转义


11. Unicode字符串:以u为前缀


12. 经常使用函数

raw_input(prompt): 获取用户输入,返回类型为字符串,尽可能使用raw_input

int(object): 将数字字符串和数字转换为整数

long(object): 将数字字符串和数字转换为长整型数

float(object): 将数字字符串和数字转换浮点数

str(object): 将值转换为合适形式的字符串

repr(object): 返回值的字符串表示

相关文章
相关标签/搜索