Python学习1

#!/usr/bin/python
# -*- coding: utf-8 -*-
# Filename : helloworld.py
print u'使用单引号定义字符串'
print u"使用双引号定义字符串"
print u'''使用三引号创建换行
第二行
第三行'''
print u'使用转义符\''
print u'使用行末\来连接太长的一行字符串\
过长部分字符串'
print ur'使用r创建自然字符串过滤转义符\''
print u'Unicode符'
print u'两个字符串自动连接' u'第二个字符串'
print u'欢迎到中国来!Hello World\''

# var
i = 5
print i
i = i + 1
print i

s = '''This is a multi-line string.
This is the second line.'''
print s

s = u'创建逻辑行,不以分号结尾'
print s

print \
      s

# calc
print 2//3
print 20/3
print 20//3
print 20//3.0
print 20/3.0
print 2<<2
print 3<<2
print 4<<2
print 3>>2
print 4>>2
print 5>>2
print 6>>2
print 5&3
print 5^3
# 加号比与或符优先级高
print 5&3 + 5^3 == 5|3
print 5&3 + 5^3
print (5&3) + (5^3)
print 5|3
print ~5
# x的值与y的值互换
x = 5
y = 3
x = x ^ y
y = y ^ x
x = x ^ y
print x
print y
x = ~(~0<<4)
y = x >> 4
print y & x
# 循环移位
a = ~0
b = a << (8 - 4)
c = a >> 4
c = c | b
print c
a = 0xAA
b = a << (8 - 4)
c = a >> 4
c = c | b
print c,a
a = 0x55
b = a << (8 - 4)
c = a >> 4
c = c | b
print c,a

原文地址:https://www.cnblogs.com/si812cn/p/1740243.html