上一页 1 ··· 55 56 57 58 59 60 61 62 63 ··· 68 下一页
摘要: import datetime base = datetime.datetime.today() for x in range(0, 5): print(base + datetime.timedelta(days=x)) 阅读全文
posted @ 2018-11-17 18:13 anobscureretreat 阅读(342) 评论(0) 推荐(0) 编辑
摘要: import datetime today = datetime.date.today() yesterday = today - datetime.timedelta(days = 1) tomorrow = today + datetime.timedelta(days = 1) print('Yesterday : ',yesterday) print('Tod... 阅读全文
posted @ 2018-11-17 18:04 anobscureretreat 阅读(626) 评论(0) 推荐(0) 编辑
摘要: from datetime import date, timedelta dt = date.today() - timedelta(5) print('Current Date :',date.today()) print('5 days before Current Date :',dt) 阅读全文
posted @ 2018-11-17 16:59 anobscureretreat 阅读(1335) 评论(0) 推荐(1) 编辑
摘要: from django.utils.http import urlquote a = urlquote('分享') print(a) 阅读全文
posted @ 2018-11-17 15:03 anobscureretreat 阅读(410) 评论(0) 推荐(0) 编辑
摘要: Document 阅读全文
posted @ 2018-11-17 14:59 anobscureretreat 阅读(294) 评论(0) 推荐(0) 编辑
摘要: def list_sum(num_List): if len(num_List) == 1: return num_List[0] else: return num_List[0] + list_sum(num_List[1:]) print(list_sum([2, 4, 5, 6, 7])) 阅读全文
posted @ 2018-11-16 20:27 anobscureretreat 阅读(2038) 评论(0) 推荐(0) 编辑
摘要: mycode = 'print("hello world")' code = """ def mutiply(x,y): return x*y print('Multiply of 2 and 3 is: ',mutiply(2,3)) """ exec(mycode) exec(code) 阅读全文
posted @ 2018-11-16 20:24 anobscureretreat 阅读(1748) 评论(0) 推荐(0) 编辑
摘要: def is_even_num(l): enum = [] for n in l: if n % 2 == 0: enum.append(n) return enum print(is_even_num([1, 2, 3, 4, 5, 6, 7, 8, 9])) 阅读全文
posted @ 2018-11-16 20:22 anobscureretreat 阅读(1576) 评论(0) 推荐(0) 编辑
摘要: def string_reverse(str1): rstr1 = '' index = len(str1) while index > 0: rstr1 += str1[ index - 1 ] index = index - 1 return rstr1 print(string_reverse('1... 阅读全文
posted @ 2018-11-16 20:20 anobscureretreat 阅读(145) 评论(0) 推荐(0) 编辑
摘要: import collections my_list = [10,10,10,10,20,20,20,20,40,40,50,50,30] print("Original List : ",my_list) ctr = collections.Counter(my_list) print("Frequency of the elements in the List : ",d... 阅读全文
posted @ 2018-11-16 20:14 anobscureretreat 阅读(3277) 评论(0) 推荐(0) 编辑
摘要: def sum_list(items): sum_numbers = 0 for x in items: sum_numbers += x return sum_numbers print(sum_list([1,2,-8])) 阅读全文
posted @ 2018-11-16 20:10 anobscureretreat 阅读(6050) 评论(0) 推荐(1) 编辑
摘要: color = ['Red', 'Green', 'White', 'Black', 'Pink', 'Yellow'] color = [x for (i,x) in enumerate(color) if i not in (0,4,5)] print(color) 阅读全文
posted @ 2018-11-16 20:07 anobscureretreat 阅读(2394) 评论(0) 推荐(0) 编辑
摘要: def multiply_list(items): tot = 1 for x in items: tot *= x return tot print(multiply_list([1,2,-8])) 阅读全文
posted @ 2018-11-16 20:05 anobscureretreat 阅读(975) 评论(0) 推荐(0) 编辑
摘要: 1.变量赋值: name=lbg 等号前后不能有空格 name="Lebron James" 变量值中有空格要用双引号 echo ${name} 用${}更保险 shopt -s -o nounset 设置“先声明再使用” 2.取消变量: unset ... 阅读全文
posted @ 2018-11-16 14:07 anobscureretreat 阅读(407) 评论(0) 推荐(0) 编辑
摘要: 一句话判断 1.判断变量 read -p "input a word :" word if [ ! -n "$word" ] ;then echo "you have not input a word!" else echo "the word you input is $word" fi 或者 # 阅读全文
posted @ 2018-11-16 13:46 anobscureretreat 阅读(1812) 评论(0) 推荐(0) 编辑
摘要: 地址栏: 输出: 阅读全文
posted @ 2018-11-16 12:37 anobscureretreat 阅读(1293) 评论(0) 推荐(0) 编辑
摘要: def long_words(n, str): word_len = [] txt = str.split(" ") for x in txt: if len(x) > n: word_len.append(x) return word_len print(long_words(3, "Th... 阅读全文
posted @ 2018-11-16 10:33 anobscureretreat 阅读(1663) 评论(0) 推荐(0) 编辑
摘要: def match_words(words): ctr = 0 for word in words: if len(word) > 1 and word[0] == word[-1]: ctr += 1 return ctr print(match_words(['abc', 'xyz', 'aba', '122771'])... 阅读全文
posted @ 2018-11-16 10:29 anobscureretreat 阅读(1268) 评论(0) 推荐(0) 编辑
摘要: def count_range_in_list(li, min, max): ctr = 0 for x in li: if min <= x <= max: ctr += 1 return ctr list1 = [10,20,30,40,40,40,70,80,99] print(count... 阅读全文
posted @ 2018-11-16 10:24 anobscureretreat 阅读(1456) 评论(0) 推荐(0) 编辑
摘要: def common_data(list1, list2): result = False for x in list1: for y in list2: if x == y: result = True return result print(common... 阅读全文
posted @ 2018-11-16 10:17 anobscureretreat 阅读(1100) 评论(0) 推荐(0) 编辑
摘要: nums = [5, 15, 35, 8, 98] for num_index, num_val in enumerate(nums): print(num_index, num_val) 阅读全文
posted @ 2018-11-16 10:12 anobscureretreat 阅读(3152) 评论(0) 推荐(0) 编辑
摘要: def is_Sublist(l, s): sub_set = False if s == []: sub_set = True elif s == l: sub_set = True elif len(s) > len(l): sub_set = False els... 阅读全文
posted @ 2018-11-16 10:09 anobscureretreat 阅读(1914) 评论(0) 推荐(0) 编辑
摘要: 输出 阅读全文
posted @ 2018-11-16 01:58 anobscureretreat 阅读(13063) 评论(0) 推荐(2) 编辑
摘要: CharField #字符串字段, 用于较短的字符串. #CharField 要求必须有一个参数 maxlength, 用于从数据库层和Django校验层限制该字段所允许的最大字符数. IntegerField #用于保存一个整数. FloatField # 一个浮点数. 必须 提供两个参数: # ... 阅读全文
posted @ 2018-11-16 01:57 anobscureretreat 阅读(377) 评论(0) 推荐(0) 编辑
摘要: from random import shuffle color = ['1', '2', '3', '4', '5'] shuffle(color) print(color) 阅读全文
posted @ 2018-11-15 21:23 anobscureretreat 阅读(974) 评论(0) 推荐(0) 编辑
摘要: #Initialize a complex number cn = complex(2,3) print("Complex Number: ",cn) print("Complex Number - Real part: ",cn.real) print("Complex Number - Imaginary part: ",cn.imag) 阅读全文
posted @ 2018-11-15 21:16 anobscureretreat 阅读(13259) 评论(0) 推荐(0) 编辑
摘要: import random print(random.choice('abcdefghijklm')) 阅读全文
posted @ 2018-11-15 21:13 anobscureretreat 阅读(3127) 评论(0) 推荐(0) 编辑
摘要: import random nums = [1, 2, 3, 4, 5, 6, 7] random.shuffle(nums) print(nums) 阅读全文
posted @ 2018-11-15 21:10 anobscureretreat 阅读(7251) 评论(0) 推荐(0) 编辑
摘要: from fractions import Fraction value = 4.2 print(Fraction(value).limit_denominator()) 阅读全文
posted @ 2018-11-15 21:07 anobscureretreat 阅读(1657) 评论(0) 推荐(0) 编辑
摘要: import math print(math.fabs(-2.1)) print(math.fabs(-0.0)) print(math.fabs(10.1)) print(math.fabs(0.0)) 阅读全文
posted @ 2018-11-15 21:03 anobscureretreat 阅读(1939) 评论(0) 推荐(0) 编辑
摘要: print("Addition of two complex numbers : ",(4+3j)+(3-7j)) print("Subtraction of two complex numbers : ",(4+3j)-(3-7j)) print("Multiplication of two complex numbers : ",(4+3j)*(3-7j)) print("D... 阅读全文
posted @ 2018-11-15 21:01 anobscureretreat 阅读(811) 评论(0) 推荐(0) 编辑
摘要: import fractions f1 = fractions.Fraction(2, 3) f2 = fractions.Fraction(3, 7) print('{} + {} = {}'.format(f1, f2, f1 + f2)) print('{} - {} = {}'.format(f1, f2, f1 - f2)) print('{} * ... 阅读全文
posted @ 2018-11-15 20:59 anobscureretreat 阅读(718) 评论(0) 推荐(0) 编辑
摘要: def is_Power_of_three(n): while (n % 3 == 0): n /= 3; return n == 1; print(is_Power_of_three(9)) print(is_Power_of_three(81)) print(is_Power_of_three(21)) ... 阅读全文
posted @ 2018-11-15 10:27 anobscureretreat 阅读(796) 评论(2) 推荐(0) 编辑
摘要: def is_Power_of_four(n): while n and not (n & 0b11): n >>= 2 return (n == 1) print(is_Power_of_four(4)) print(is_Power_of_four(16)) print(is_Power_of_four(255)) 阅读全文
posted @ 2018-11-15 10:23 anobscureretreat 阅读(799) 评论(0) 推荐(0) 编辑
摘要: def is_arithmetic(l): delta = l[1] - l[0] for index in range(len(l) - 1): if not (l[index + 1] - l[index] == delta): return False return True print(i... 阅读全文
posted @ 2018-11-15 10:20 anobscureretreat 阅读(3806) 评论(0) 推荐(0) 编辑
摘要: def is_geometric(li): if len(li) <= 1: return True # Calculate ratio ratio = li[1]/float(li[0]) # Check the ratio of the remaining for i in range(1, len(li))... 阅读全文
posted @ 2018-11-15 10:15 anobscureretreat 阅读(2375) 评论(0) 推荐(0) 编辑
摘要: def add_binary_nums(x,y): max_len = max(len(x), len(y)) x = x.zfill(max_len) y = y.zfill(max_len) result = '' carry = 0 for i in... 阅读全文
posted @ 2018-11-15 10:06 anobscureretreat 阅读(2790) 评论(0) 推荐(0) 编辑
摘要: python manage.py makemigrations python manage.py migrate 阅读全文
posted @ 2018-11-14 23:55 anobscureretreat 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 有时我们需要将特定操作封装成服务,通过服务启动停止,例如nginx的启动停止,service nginx start 或者service nginx stop 下面我们将编写一个demo sudo vi test,建立一个service名称为test的服务 加入下面模版代码 可以根据需要编写star 阅读全文
posted @ 2018-11-14 22:28 anobscureretreat 阅读(1896) 评论(0) 推荐(0) 编辑
摘要: 执行命令 阅读全文
posted @ 2018-11-14 17:46 anobscureretreat 阅读(735) 评论(0) 推荐(0) 编辑
上一页 1 ··· 55 56 57 58 59 60 61 62 63 ··· 68 下一页