投稿

2月 27, 2021の投稿を表示しています

The Zen of Python

Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those! The meaning of the 6th line is as follows. Sparse is better than dense. — In short, “don't try to stick too much code on one line.” [X] Although efficien...

Sequence Types -- str, unicode, list, tuple, buffer, xrange

イメージ
There are six sequence types: strings, Unicode strings, lists, tuples, buffers, and xrange objects. This table lists the sequence operations sorted in ascending priority (operations in the same box have the same priority). In the table, s and t are sequences of the same type; n, i and j are integers: from here

time モジュール & datetime モジュール

import time as t now=t.localtime() print('localtime()') print(now) print() print("t.strftime('%y-%m-%d %H:%M:%S',now)") print(t.strftime('%y-%m-%d %H:%M:%S',now)) import datetime as dt nowdt= dt.datetime.now() print() print('nowdt') print(nowdt) print('nowdt.isoformat()') print(nowdt.isoformat()) nextyear=dt.datetime(2022,1,1) print() print('delta.days') delta=nextyear-nowdt print(delta.days) ==== RESTART: C:/python/time&datetimeTest.py === localtime() time.struct_time(tm_year=2021, tm_mon=2, tm_mday=28, tm_hour=10, tm_min=37, tm_sec=53, tm_wday=6, tm_yday=59, tm_isdst=0) t.strftime('%y-%m-%d %H:%M:%S',now) 21-02-28 10:37:53 nowdt 2021-02-28 10:37:53.398604 nowdt.isoformat() 2021-02-28T10:37:53.398604 delta.days 306 >>>