print r'''"To be, or not to be":that is the question.
Whether it's nobler in the mind to suffer.'''
Whether it's nobler in the mind to suffer.'''
2019-01-23
s = 'Python was started in 1989 by \"Guido\". ' '\nPython is free and easy to learn.'
print s
print s
2019-01-23
s = 'Python was started in 1989 by \"Guido\". \n Python is free and easy to learn.'
print s
print s
2019-01-23
x1 = 1
d = 3
n = 100
x100 = x1 + (n-1)*d
s = (x1 + x100)*n/2
print s
d = 3
n = 100
x100 = x1 + (n-1)*d
s = (x1 + x100)*n/2
print s
2019-01-23
a = 'python'
print 'hello,', a or 'world'
# 短路计算or的情况下, a 的值为True,返回 a
b = ''
print 'hello,', b or 'world'
#短路计算or的情况下, b的值为false, 则返回 world
print 'hello,', a or 'world'
# 短路计算or的情况下, a 的值为True,返回 a
b = ''
print 'hello,', b or 'world'
#短路计算or的情况下, b的值为false, 则返回 world
2019-01-23
python3
L = list(range(1, 101))
print (L[:10])
print (L[2:100:3])
print (L[4:50:5])
L = list(range(1, 101))
print (L[:10])
print (L[2:100:3])
print (L[4:50:5])
2019-01-23
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in zip(range(1,5),L):
print index, '-', name
for index, name in zip(range(1,5),L):
print index, '-', name
3.x版本的是直接可以计算出来的 不需要把整数10变成浮点数10.0
11 //4 # ==> 2 取整数
11 % 4 # ==> 3 取余数
111/ 4 # ==> 2.75 得到结果
11 //4 # ==> 2 取整数
11 % 4 # ==> 3 取余数
111/ 4 # ==> 2.75 得到结果
2019-01-22
sum = 0
x = 1
while x < 100:
sum = sum + x
x = x + 2
print sum
x = 1
while x < 100:
sum = sum + x
x = x + 2
print sum
2019-01-22
L = ['Adam', 'Lisa', 'Bart']
L[0], L[2] = L[-1], L[-3]
print L
L[0], L[2] = L[-1], L[-3]
print L
2019-01-22
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for (x,y) in s:
print x,':',y
for (x,y) in s:
print x,':',y
2019-01-21
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2==0:
continue
sum=x+sum
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2==0:
continue
sum=x+sum
print sum
2019-01-21