def firstCharUpper(s):
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2015-07-23
L = range(1, 101)
print L[0:10]
print L[2:100:3]
print L[4:50:5]
#起始索引,结束索引,步长
print L[0:10]
print L[2:100:3]
print L[4:50:5]
#起始索引,结束索引,步长
2015-07-23
import math
def quadratic_equation(a, b, c):
y = math.sqrt(b * b - 4 * a * c)
if y>=0:
x1 = (-b + y) / (2 * a)
x2 = (-b - y) / (2 * a)
else:
print 'error'
return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
#数学是硬伤、、、、已经忘了!!!
def quadratic_equation(a, b, c):
y = math.sqrt(b * b - 4 * a * c)
if y>=0:
x1 = (-b + y) / (2 * a)
x2 = (-b - y) / (2 * a)
else:
print 'error'
return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
#数学是硬伤、、、、已经忘了!!!
2015-07-23
def square_of_sum(L):
sum=0
for i in L:
sum+=i**2
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
sum=0
for i in L:
sum+=i**2
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-07-23
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
print x[0]+':'+str(x[1])
for x in s:
print x[0]+':'+str(x[1])
2015-07-23
s = set(['adam', 'lisa', 'bart', 'paul'])
print 'adam' in s
print 'bart' in s
print 'adam' in s
print 'bart' in s
2015-07-23
sum = 0
n = 0
while True:
sum+=2**(n-1)
n=n+1
if n>20:
break
print sum
n = 0
while True:
sum+=2**(n-1)
n=n+1
if n>20:
break
print sum
2015-07-23
Python把0、空字符串''和None看成 False,其他数值和非空字符串都看成
所以a=>True b=>False
所以a=>True b=>False
2015-07-23
已采纳回答 / liusongsir
因为for循环这里遍历出来的是3个tuple,分别是('Adam', 95),('Lisa', 85),('Bart', 59),然后每个tuple包含两个元素,因为tuple是有序集合,所以可以通过下标访问,下标从0开始,所以x[0]就是'姓名',x[1]就是'分数'。而你说的为什么s[0]不行,这是因为set是无序集合,不能通过下标访问
2015-07-23