python中字符串使用单引号或双引号包裹,当要打印单引号或双引号时需要使用转义字符,即在前面添加/
例
print ' he said: " I \' m tom " . ' print " he said: \" I'm tom \" . " print ' he said :\'I \' m tom \' ' print "he said :' I \" m tom' " print 'he said :"I " m tom " '
he said: " I ' m tom " . he said: " I'm tom " . he said :'I ' m tom ' he said :' I " m tom' he said :"I " m tom "
he said :"I " m tom "
如果字符串里面有很多字符都需要转义,就需要加很多\
,为了简化,Python还允许用r''
表示''
内部的字符串默认不转义
print '\\\t-end' print r'\\\t-end'
\ -end \\\t-end
python 与或非
# -*- coding: utf-8 -*- print True and True print True or True print not True print False and False print False or False print not False print True and False print True or False
True True False False False True False True
多行字符串
print '''hello 小明。 你好, Tom \t天气不错,出去\n走走? '''
hello 小明。 你好, Tom 天气不错,出去 走走?
变量可以被赋值为任意类型
# -*- coding: utf-8 -*- x=10 print x x='hello' print x
10 hello
python的整数除法(/)在python前后结果可能不一致,在2.7中 10/3的值为3