摘要:
在大神麦金尼的著作中,对 np.logical_and、np.logical_or、np.logical_xor 三个二元通用函数的说明是:Computer element_wise true value of logical operateion (equivalent to infix oper 阅读全文
摘要:
示例1: print(' ', end='') for i in range(1, 10): print(str(i).rjust(3), end='') print() for i in range(1, 10): print(i, end='') for j in range(1, 10): i 阅读全文
摘要:
Python 的简洁真是很好,R 语言的 ifelse 语句和 循环结构嵌套两层就给搞得晕了。 打印这样的一个图形: python 代码: for i in range(4): for j in range(i+3): if j == 0 or j == i+2: print('#'*(i+3), 阅读全文
摘要:
自定义函数代码: def p4(x): for j in range(x+1): for i in range(x+1): if j > i and j > x - i: print('下'.rjust(2), end='') elif j > i and j < x - i: print('左'. 阅读全文
摘要:
利用 for 循环打印如下的 九九乘法表 print(' ', end='') for i in range(1, 10): print(str(i).rjust(3), end='') print() for i in range(1, 10): x = i print(i, end='') fo 阅读全文
摘要:
一、以文本形式保存数据 import string from collections import Counter s = string.ascii_letters with open('test.txt', 'w') as file: for i in range(len(s)): print(s 阅读全文
摘要:
reduce(func, seq) 函数对序列中的元素进行递归运算。在 3.x 的 python 中 需要从 functools 模块中导入。 求 1~100 的和 用 for 循环实现上面的求和过程,代码如下: s = 0 for i in range(1, 101): s += i s 阅读全文
摘要:
方法一: def duplicated_count(text): result=[] text=text.lower() for i in text: if text.count(i) > 1 and i not in result: result.append(i) return len(resu 阅读全文
摘要:
方法一: def alter_case(string): new="" for i in string: if i.isupper(): new+=i.lower() elif i.islower(): new+=i.upper() else: new+=i return new 调用函数: alt 阅读全文