您的位置:首页 > 编程语言 > Python开发

Python 知识点 记录 日积月累

2015-11-21 10:05 656 查看

输出序列以及倒序输出

[code]print range(1,10)
print range(1,10)[::-1]
#output:
#[1, 2, 3, 4, 5, 6, 7, 8, 9]
#[9, 8, 7, 6, 5, 4, 3, 2, 1]


加 r 不转义

[code]print "\\savc\nff"
print r"\\savc\nff"
#output:
#\savc
#ff
#\\savc\nff


格式化 对其输出 log 信息

[code]print 'succeed'.center(20,'=')
print 'fail'.center(20,'=')
# output
# ======succeed=======
# ========fail========


单引号和双引号都可以表示字符串

[code]print 'hello world'
print "hello world"


都是输出

hello world


这点要注意和java区分,因为java单引号表示字符
char
,双引号表示字符串
str


pass的使用

如果想定义一个空函数,可以这样:

[code]def staCorrect():
    pass


如果把上面的pass去掉是会报错的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: