a or "world" a为非空字符串所以表达式返回a
b or "world" b为空字符串所以表达式返回b
b or "world" b为空字符串所以表达式返回b
2015-06-26
最赞回答 / Jeffacode
并没有什么"这种情况用这个,那种情况用那个"一说。print(a, b)的意思就是:<...code...>只不过两者以空格' '隔开而不是分行符'\n'。更深入的话,print()还接收一个参数叫sep,就是两者以什么结尾<...code...>而print(a+b)说白了就是:<...code...>只不过要注意a和b是否能进行+操作,python有『多态』一说,同样的+对两个int就是加法,对两个str就是连接操作,这点上的确比c语言方便的多
2015-06-25
def firstCharUpper(s):
return s[:1].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[:1].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2015-06-25
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2==0:
continue
sum=sum+x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2==0:
continue
sum=sum+x
print sum
2015-06-25
sum = 0
x = 1
n = 1
while True:
x=2**(n-1)
sum=sum+x
n=n+1
if n>20:
break
print sum
x = 1
n = 1
while True:
x=2**(n-1)
sum=sum+x
n=n+1
if n>20:
break
print sum
2015-06-25
print "hello,python."
print "hello,","python." //会多输出一个空格
print 'hello,''python'
print "hello,","python." //会多输出一个空格
print 'hello,''python'
2015-06-24