>>> print('holo,',b or 'world')
holo, world
>>> print('holo',b or 'world')
holo world
>>> a='python'
>>> print('holo',a or 'world')
holo python
>>> print('holo,',a or 'world')
holo, python
holo, world
>>> print('holo',b or 'world')
holo world
>>> a='python'
>>> print('holo',a or 'world')
holo python
>>> print('holo,',a or 'world')
holo, python
2023-12-30
# Enter a code
def greet(what = 'world'):
print('Hello,{}'.format(what))
def greet(what = 'world'):
print('Hello,{}'.format(what))
2023-12-27
# Enter a code
def func(x):
if isinstance(x, list):
return sum(x)
elif isinstance(x, tuple):
multi = 1
for n in x:
multi *= n
return multi
def func(x):
if isinstance(x, list):
return sum(x)
elif isinstance(x, tuple):
multi = 1
for n in x:
multi *= n
return multi
2023-12-27
# coding=utf-8
def sum_func(n):
if n <= 1:
return 1
else:
return (n + sum_func(n-1))
def sum_for():
total = 0
for n in range(1, 101):
total += n
return total
def sum_func(n):
if n <= 1:
return 1
else:
return (n + sum_func(n-1))
def sum_for():
total = 0
for n in range(1, 101):
total += n
return total
2023-12-27
# Enter a code
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
if not s1.isdisjoint(s2):
print(s1.intersection(s2))
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
if not s1.isdisjoint(s2):
print(s1.intersection(s2))
2023-12-27
# Enter a code
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for n in L:
if n not in S:
S.add(n)
else:
S.remove(n)
print(S)
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for n in L:
if n not in S:
S.add(n)
else:
S.remove(n)
print(S)
2023-12-27
# Enter a code
L = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
L.append('Zero')
L.append('Phoebe')
L.append('Gen')
L.sort()
print(L)
L = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
L.append('Zero')
L.append('Phoebe')
L.append('Gen')
L.sort()
print(L)
2023-12-27
T = ('Alice', 'Bob', 'Candy', 'David', 'Ellena')
# 通過下標的方式訪問元素
print(T[0]) # ==> Alice
print(T[4]) # ==> Ellena
# 切片
print(T[1:3]) # ==> ('Bob', 'Candy')
candy錯了吧,應該是David吧
# 通過下標的方式訪問元素
print(T[0]) # ==> Alice
print(T[4]) # ==> Ellena
# 切片
print(T[1:3]) # ==> ('Bob', 'Candy')
candy錯了吧,應該是David吧
2023-12-25
num = 3.14 * 1.57
print (round (num , 2))
round 需要嵌套在print里面
print (round (num , 2))
round 需要嵌套在print里面
2023-12-19