一、help
运行
help('len')
可以显示出有关 len
函数的帮助;按下 q键
可以推出帮助;
运行
help()
可以了解关于 help
本身的更多信息;
二、注释
python 可以通过 #
来注释代码
# 注意 print 是一个函数
print('Hello world! ')
三、字符类型
1、数字
分为两个类型——整数(integers)与浮点数(floats)
2、字符串
- 使用单引号来指定字符串;
‘Quote me on this,or this“ haha’
- 使用双引号来指定字符串,效果与单引号是一样的;
“像这样,还有可以使用‘ ”
- 使用三引号来指定多行字符串,在三引号之间,可以使用单引号和双引号
'''
This is the first line
"What's your name?", I asked
He said,"Bond, James Bond"
'''
效果
This is the first line
"What's your name?", I asked
He said,"Bond, James Bond"
四、字符串格式化方法
1、format格式化函数
菜鸟教程format格式化函数
format函数可以接受不限个参数,位置也可以不按顺序
(1)不限参数,不设参数,指定位置
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))
输出:
Swaroop was 20 years old when he wrote this book
Why is Swaroop playing with that python?
(2)不限参数,默认顺序
age = 20
name = 'Swaroop'
print('{} was {} years old when he wrote this book'.