随笔分类 -  python

上一页 1 ··· 38 39 40 41 42 43 44 45 46 ··· 48 下一页
摘要:def convertToBinary(n): """Function to print binary number for the input decimal using recursion""" if n > 1: convertToBinary(n//2) print(n % 2,end = '') # decimal number dec = ... 阅读全文
posted @ 2018-11-19 19:58 anobscureretreat 阅读(1356) 评论(0) 推荐(0) 编辑
摘要:# Program to generate a random number between 0 and 9 # import the random module import random print(random.randint(0,9)) 阅读全文
posted @ 2018-11-19 19:54 anobscureretreat 阅读(169) 评论(0) 推荐(0) 编辑
摘要:import platform import os print(os.name) print(platform.system()) print(platform.release()) 阅读全文
posted @ 2018-11-19 19:52 anobscureretreat 阅读(253) 评论(0) 推荐(0) 编辑
摘要:from datetime import date f_date = date(2014, 7, 2) l_date = date(2014, 7, 11) delta = l_date - f_date print(delta.days) 阅读全文
posted @ 2018-11-19 19:47 anobscureretreat 阅读(1119) 评论(0) 推荐(1) 编辑
摘要:# For 32 bit it will return 32 and for 64 bit it will return 64 import struct print(struct.calcsize("P") * 8) 阅读全文
posted @ 2018-11-19 19:43 anobscureretreat 阅读(612) 评论(0) 推荐(0) 编辑
摘要:import os # Access all environment variables print('*---------------ENVIRON-------------------*') print(os.environ) print('*----------------HOME------------------*') # Access a particula... 阅读全文
posted @ 2018-11-19 19:41 anobscureretreat 阅读(4292) 评论(0) 推荐(0) 编辑
摘要:class Rectangle(): def __init__(self, l, w): self.length = l self.width = w def rectangle_area(self): return self.length*self.width newRectangle =... 阅读全文
posted @ 2018-11-19 19:36 anobscureretreat 阅读(261) 评论(0) 推荐(0) 编辑
摘要:新建test.py 运行 然后查看当前目录的runtest.log,会看到下面的结果 阅读全文
posted @ 2018-11-19 18:29 anobscureretreat 阅读(133) 评论(0) 推荐(0) 编辑
摘要:my_dict = {'data1':100,'data2':-54,'data3':247} result=1 for key in my_dict: result=result * my_dict[key] print(result) 阅读全文
posted @ 2018-11-19 10:30 anobscureretreat 阅读(1559) 评论(0) 推荐(0) 编辑
摘要:keys = ['red', 'green', 'blue'] values = ['#FF0000','#008000', '#0000FF'] color_dictionary = dict(zip(keys, values)) print(color_dictionary) 阅读全文
posted @ 2018-11-19 10:27 anobscureretreat 阅读(691) 评论(0) 推荐(0) 编辑
摘要:d = {'x': 10, 'y': 20, 'z': 30} for dict_key, dict_value in d.items(): print(dict_key,'->',dict_value) 阅读全文
posted @ 2018-11-19 10:25 anobscureretreat 阅读(8262) 评论(0) 推荐(0) 编辑
摘要:my_dict = {'x':500, 'y':5874, 'z': 560} key_max = max(my_dict.keys(), key=(lambda k: my_dict[k])) key_min = min(my_dict.keys(), key=(lambda k: my_dict[k])) print('Maximum Value: ',my_di... 阅读全文
posted @ 2018-11-19 10:23 anobscureretreat 阅读(2579) 评论(0) 推荐(0) 编辑
摘要:dic1={1:10, 2:20} dic2={3:30, 4:40} dic3={5:50,6:60} dic4 = {} for d in (dic1, dic2, dic3): dic4.update(d) print(dic4) 阅读全文
posted @ 2018-11-19 10:16 anobscureretreat 阅读(185) 评论(0) 推荐(0) 编辑
摘要:d = {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60} def is_key_present(x): if x in d: print('Key is present in the dictionary') else: print('Key is not present in the dictionar... 阅读全文
posted @ 2018-11-19 10:15 anobscureretreat 阅读(1954) 评论(0) 推荐(0) 编辑
摘要:my_dict = {} if not bool(my_dict): print("Dictionary is empty") 阅读全文
posted @ 2018-11-19 10:12 anobscureretreat 阅读(25522) 评论(0) 推荐(1) 编辑
摘要:d = {0:10, 1:20} print(d) d.update({2:30}) print(d) 阅读全文
posted @ 2018-11-19 10:11 anobscureretreat 阅读(841) 评论(0) 推荐(0) 编辑
摘要:class dictObj(object): def __init__(self): self.x = 'red' self.y = 'Yellow' self.z = 'Green' def do_nothing(self): pass test = dictObj() ... 阅读全文
posted @ 2018-11-19 10:04 anobscureretreat 阅读(3276) 评论(0) 推荐(0) 编辑
摘要:import datetime print(datetime.datetime.now().time()) 阅读全文
posted @ 2018-11-17 18:17 anobscureretreat 阅读(159) 评论(0) 推荐(0) 编辑
摘要: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 阅读(632) 评论(0) 推荐(0) 编辑

上一页 1 ··· 38 39 40 41 42 43 44 45 46 ··· 48 下一页