摘要:
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
阅读(347)
推荐(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
阅读(636)
推荐(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
阅读(1373)
推荐(1)
摘要:
from django.utils.http import urlquote a = urlquote('分享') print(a)
阅读全文
posted @ 2018-11-17 15:03
anobscureretreat
阅读(422)
推荐(0)
posted @ 2018-11-17 14:59
anobscureretreat
阅读(298)
推荐(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
阅读(2055)
推荐(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
阅读(1755)
推荐(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
阅读(1590)
推荐(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
阅读(153)
推荐(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
阅读(3317)
推荐(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
阅读(6061)
推荐(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
阅读(2401)
推荐(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
阅读(1011)
推荐(0)
摘要:
1.变量赋值: name=lbg 等号前后不能有空格 name="Lebron James" 变量值中有空格要用双引号 echo ${name} 用${}更保险 shopt -s -o nounset 设置“先声明再使用” 2.取消变量: unset ...
阅读全文
posted @ 2018-11-16 14:07
anobscureretreat
阅读(423)
推荐(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
阅读(1844)
推荐(0)
posted @ 2018-11-16 12:37
anobscureretreat
阅读(1308)
推荐(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
阅读(1675)
推荐(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
阅读(1283)
推荐(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
阅读(1466)
推荐(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
阅读(1120)
推荐(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
阅读(3162)
推荐(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
阅读(1944)
推荐(0)
posted @ 2018-11-16 01:58
anobscureretreat
阅读(13077)
推荐(2)
摘要:
CharField #字符串字段, 用于较短的字符串. #CharField 要求必须有一个参数 maxlength, 用于从数据库层和Django校验层限制该字段所允许的最大字符数. IntegerField #用于保存一个整数. FloatField # 一个浮点数. 必须 提供两个参数: # ...
阅读全文
posted @ 2018-11-16 01:57
anobscureretreat
阅读(406)
推荐(0)
摘要:
from random import shuffle color = ['1', '2', '3', '4', '5'] shuffle(color) print(color)
阅读全文
posted @ 2018-11-15 21:23
anobscureretreat
阅读(978)
推荐(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
阅读(13307)
推荐(0)
摘要:
import random print(random.choice('abcdefghijklm'))
阅读全文
posted @ 2018-11-15 21:13
anobscureretreat
阅读(3147)
推荐(0)
摘要:
import random nums = [1, 2, 3, 4, 5, 6, 7] random.shuffle(nums) print(nums)
阅读全文
posted @ 2018-11-15 21:10
anobscureretreat
阅读(7263)
推荐(0)
摘要:
from fractions import Fraction value = 4.2 print(Fraction(value).limit_denominator())
阅读全文
posted @ 2018-11-15 21:07
anobscureretreat
阅读(1674)
推荐(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
阅读(1952)
推荐(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
阅读(818)
推荐(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
阅读(732)
推荐(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
阅读(816)
推荐(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
阅读(816)
推荐(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
阅读(3827)
推荐(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
阅读(2396)
推荐(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
阅读(2813)
推荐(0)
摘要:
python manage.py makemigrations python manage.py migrate
阅读全文
posted @ 2018-11-14 23:55
anobscureretreat
阅读(166)
推荐(0)
摘要:
有时我们需要将特定操作封装成服务,通过服务启动停止,例如nginx的启动停止,service nginx start 或者service nginx stop 下面我们将编写一个demo sudo vi test,建立一个service名称为test的服务 加入下面模版代码 可以根据需要编写star
阅读全文
posted @ 2018-11-14 22:28
anobscureretreat
阅读(1975)
推荐(0)
posted @ 2018-11-14 17:46
anobscureretreat
阅读(745)
推荐(0)