a = 'python' , a为True。print('hello,', a or 'world') 或计算中字串符结果是False,所以显示结果为a=‘python’。b = '',b是空值,print('hello,', b or 'world'),或计算中不显示空值,是以结果显示为world。
2021-01-10
def sub_sum(L):
sum1=0
sum2=0
for a in L:
if a%2==0:
sum1=sum1+a
else:
sum2=sum2+a
return sum1,sum2
L=[1,2,3,4]
b=sub_sum(L)
print(b)
sum1=0
sum2=0
for a in L:
if a%2==0:
sum1=sum1+a
else:
sum2=sum2+a
return sum1,sum2
L=[1,2,3,4]
b=sub_sum(L)
print(b)
2021-01-10
hello='Hello'
space=' '
world='World'
print(hello+space+world)
space=' '
world='World'
print(hello+space+world)
2021-01-09
L=[75,92,59,68,99]
sum=0.0
for ch in L:
sum=sum+ch
print(sum/5)
sum=0.0
for ch in L:
sum=sum+ch
print(sum/5)
2021-01-07
age=8
if age>=18:
print('adult')
elif age>=6:
print('teenager')
elif age>=3:
print('kid')
else:
print('baby')
if age>=18:
print('adult')
elif age>=6:
print('teenager')
elif age>=3:
print('kid')
else:
print('baby')
2021-01-07
age=8
if age>=18:
print('adult')
elif age>=6:
print('teenager')
elif age>=3:
print('kid')
else:
print('baby')
if age>=18:
print('adult')
elif age>=6:
print('teenager')
elif age>=3:
print('kid')
else:
print('baby')
2021-01-07
>>> dongdongqiang=19
>>> if dongdongqiang>18:
... print('adult')
...
adult
>>> if dongdongqiang>18:
... print('adult')
...
adult
2021-01-07
>>> s='AABCDEFGHHIJ'
>>> abcdefgh=s[1:9]
>>> print(abcdefgh)
ABCDEFGH
>>> abcdefgh=s[1:9]
>>> print(abcdefgh)
ABCDEFGH
2021-01-07
>>> s1='这是一句中英文混合的Python字符串:Hello World!'
>>> print(s1)
这是一句中英文混合的Python字符串:Hello World!
>>> print(s1)
这是一句中英文混合的Python字符串:Hello World!
2021-01-07
T = ((1+2), ((1+2),), ('a'+'b'), (1, ), (1,2,3,4,5))
for a in T:
print(type(a))
结果:
<class 'int'>
<class 'tuple'>
<class 'str'>
<class 'tuple'>
<class 'tuple'>
所以是3个
for a in T:
print(type(a))
结果:
<class 'int'>
<class 'tuple'>
<class 'str'>
<class 'tuple'>
<class 'tuple'>
所以是3个
2021-01-07
>>> template='Life is short,you need {}'
>>> a='Python'
>>> result=template.format(a)
>>> print(result)
Life is short,you need Python
或者
>>> template='Life is short,{}'
>>> a='you need Python'
>>> result=template.format(a)
>>> print(result)
Life is short,you need Python
>>> a='Python'
>>> result=template.format(a)
>>> print(result)
Life is short,you need Python
或者
>>> template='Life is short,{}'
>>> a='you need Python'
>>> result=template.format(a)
>>> print(result)
Life is short,you need Python
2021-01-07