Python学习笔记
1. python 获取帮助 例如help('print') 退出帮助q键
2. 注释使用#
print('hello world') #注意到print是一个函数
3. 52.3E-4 其中E表示10的幂,python没有单独的long类型,int类型可以指任何大小的整数。
4. 可以使用单引号和双引号指定字符串
‘将我这样框进来’或‘Quote me on this’ "what's your name ?"
5. 使用三个引号"""或者'''来指定多行字符串
6. 打印print函数,格式化打印方法.format()
# str_format.py
age = 20
name = 'Swaroop'
print('{0} was {1} years old when he wrote this book'.format(name, age))
print('why is {0} playing with that python?'.format(name))
print('{} was {} years old when he wrote this book'.format(name, age))
print('why is {} playing with that python?'.format(name))
7. print默认加换行符\n ,可以用end=''指定以空白结尾
8. 转义字符\,\t制表符。
9. 很长的代码可以用反斜杠\拆成多个物理行
10. r或R来指定原始(Raw)字符串
r"Newlines are indicated by \n"
11. 变量(variables) 不需要声明或者定义数据类型
12. python将程序中的任何内容统称为对象(object)
13. 默认一个物理行就是逻辑行,若指多逻辑行加分号(;),不建议这样用
14. 缩进4个空格表示一个语句块
# var.py
i = 5
print(i)
i = i + 1
print(i)
s = ''' This is a multi-line string.
This is the second line.'''
print(s)
输出:
5
6
This is a multi-line string.
This is the second line.
---------------------