摘要:
提醒:在python3中,reduce被移到了functools里面 from functools import reduce str1 = 'the quick brown fox' str2 = ' jumps over ' str3 = 'the lazy dog.' print(reduce 阅读全文
摘要:
my_set = set() #create a new set, 虽然set的显示结果为{item, item1...},但是不能用{}来创建集合,应该{}默认是创建dict print(help(my_set)) #查看帮助 my_set.add('jerry') #添加元素用add,而非lis 阅读全文
摘要:
#!/bin/bash #用while loop计算1到100的和 num=1 sum=0 while [ $num -lt 101 ]; do sum=$(($sum+$num)) num=$(($num+1)) done printf "sum is %s\n" $sum #!/bin/bash 阅读全文
摘要:
vim打开 vim ~/.vimrc 添加 syntax on #语法高亮set number #显示行数 set hlsearch set tabstop=4 set autoindent 阅读全文
摘要:
当需要输入密码时,为了保证密码不在屏幕上显示出来,可以考虑import getpass from getpass import getpass username = input('input your username: ') if username == 'jerry': password = g 阅读全文
摘要:
Python: #计算并输出1~100之间的奇数之和与偶数之和 from functools import reduce print("evenSum=",end='') print(reduce(lambda a, b: a + b, filter(lambda i: i%2 == 0, [i f 阅读全文
摘要:
1. #快速生成1,2,3,..., 100数字列表: print([i for i in range(1,101)]) 2. #快速生成001,002,003,...,100数字列表: print([f"{i:03}" for i in range(1,101)]) 或者不用f-string pr 阅读全文
摘要:
Java import java.util.Scanner; public class compare { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print 阅读全文
摘要:
用Python处理/生成JSON文件 先看个python list/array: my_list = [ {"Jerry": {"job": "comedian", "age": 34, "married": True,},}, {"Elaine": {"job": "housewife", "ag 阅读全文
摘要:
String.format(); System.out.printf(); System.out.format() 阅读全文