随笔分类 - python
摘要: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 = ...
阅读全文
摘要:# Program to generate a random number between 0 and 9 # import the random module import random print(random.randint(0,9))
阅读全文
摘要:import platform import os print(os.name) print(platform.system()) print(platform.release())
阅读全文
摘要:from datetime import date f_date = date(2014, 7, 2) l_date = date(2014, 7, 11) delta = l_date - f_date print(delta.days)
阅读全文
摘要:# For 32 bit it will return 32 and for 64 bit it will return 64 import struct print(struct.calcsize("P") * 8)
阅读全文
摘要:import os # Access all environment variables print('*---------------ENVIRON-------------------*') print(os.environ) print('*----------------HOME------------------*') # Access a particula...
阅读全文
摘要:class Rectangle(): def __init__(self, l, w): self.length = l self.width = w def rectangle_area(self): return self.length*self.width newRectangle =...
阅读全文
摘要:新建test.py 运行 然后查看当前目录的runtest.log,会看到下面的结果
阅读全文
摘要:my_dict = {'data1':100,'data2':-54,'data3':247} result=1 for key in my_dict: result=result * my_dict[key] print(result)
阅读全文
摘要:keys = ['red', 'green', 'blue'] values = ['#FF0000','#008000', '#0000FF'] color_dictionary = dict(zip(keys, values)) print(color_dictionary)
阅读全文
摘要:d = {'x': 10, 'y': 20, 'z': 30} for dict_key, dict_value in d.items(): print(dict_key,'->',dict_value)
阅读全文
摘要: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...
阅读全文
摘要: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)
阅读全文
摘要: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...
阅读全文
摘要:my_dict = {} if not bool(my_dict): print("Dictionary is empty")
阅读全文
摘要:d = {0:10, 1:20} print(d) d.update({2:30}) print(d)
阅读全文
摘要:class dictObj(object): def __init__(self): self.x = 'red' self.y = 'Yellow' self.z = 'Green' def do_nothing(self): pass test = dictObj() ...
阅读全文
摘要:import datetime print(datetime.datetime.now().time())
阅读全文
摘要:import datetime base = datetime.datetime.today() for x in range(0, 5): print(base + datetime.timedelta(days=x))
阅读全文
摘要:import datetime today = datetime.date.today() yesterday = today - datetime.timedelta(days = 1) tomorrow = today + datetime.timedelta(days = 1) print('Yesterday : ',yesterday) print('Tod...
阅读全文