print r'''"To be,or not to ":
that is the question.
Whether it's no bler in the mind to suffer'''
that is the question.
Whether it's no bler in the mind to suffer'''
2015-12-13
s = 'Phthon was started in 1989 by "Gudio".\n'
d='Python is free and easy to learn. '
print s
print d
d='Python is free and easy to learn. '
print s
print d
2015-12-13
# -*- coding: utf-8 -*-
d = {
95: "Adam",
85: 'Lisa',
59: 'Bart'
}
这样也会报错!!
d = {
95: "Adam",
85: 'Lisa',
59: 'Bart'
}
这样也会报错!!
2015-12-13
d = {
95: 'Adam',
85: 'Lisa',
59: 'Bart'
}
print d
95: 'Adam',
85: 'Lisa',
59: 'Bart'
}
print d
2015-12-13
def greet(key = 'world'):
print('Hello, ' + key + '.')
greet()
greet('Bart')
print('Hello, ' + key + '.')
greet()
greet('Bart')
2015-12-13
def greet(xxx = 'world'):
if xxx != 'world':
return 'Hello, ' + xxx + '.'
else:
return 'Hello, world.'
print(greet())
print(greet('Bart'))
if xxx != 'world':
return 'Hello, ' + xxx + '.'
else:
return 'Hello, world.'
print(greet())
print(greet('Bart'))
2015-12-13
def fact(n):
if n==1:
return 1
return n * fact(n - 1)
这个递归函数,本机亲测最大支持998,值再大就报错了。
if n==1:
return 1
return n * fact(n - 1)
这个递归函数,本机亲测最大支持998,值再大就报错了。
2015-12-13
import math
def quadratic_equation(a, b, c):
t = b * b - 4 * a * c
if t < 0:
return '该二次方程无解!'
else:
x1 = (-b + math.sqrt(t)) / (2 * a)
x2 = (-b - math.sqrt(t)) / (2 * a)
return x1, x2
print(quadratic_equation(2, 3, 0))
print(quadratic_equation(1, -6, 5))
def quadratic_equation(a, b, c):
t = b * b - 4 * a * c
if t < 0:
return '该二次方程无解!'
else:
x1 = (-b + math.sqrt(t)) / (2 * a)
x2 = (-b - math.sqrt(t)) / (2 * a)
return x1, x2
print(quadratic_equation(2, 3, 0))
print(quadratic_equation(1, -6, 5))
2015-12-13
for x in [1,2,3,4,5,6,7,8,9,]:
for y in [1,2,3,4,5,6,7,8,9]:
if x<y:
print x,y
for y in [1,2,3,4,5,6,7,8,9]:
if x<y:
print x,y
2015-12-12
sum = 0
x = 1
n = 1
while True:
sum=n
n=n*2
x=x+1
if x>21:
sum=sum-1
break
print sum
哈哈哈
x = 1
n = 1
while True:
sum=n
n=n*2
x=x+1
if x>21:
sum=sum-1
break
print sum
哈哈哈
2015-12-12
有两种方式完成。
L.insert(-1,'paul')或L.insert(2,'paul')
L.insert(-1,'paul')或L.insert(2,'paul')
2015-12-12
Python 3.5.1不会这样。
print 4/5 #==>0.8
print 4.0/5 #==>0.8
结果都是浮点数。
print 4/5 #==>0.8
print 4.0/5 #==>0.8
结果都是浮点数。
2015-12-12
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print(key + ':', d[key])
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print(key + ':', d[key])
2015-12-11