"Python"의 두 판 사이의 차이
ph
| 1번째 줄: | 1번째 줄: | ||
| + | ==Time== | ||
| + | >>> import time | ||
| + | >>> time.time() | ||
| + | 1491792653.410371 | ||
| + | >>> import datetime | ||
| + | >>> datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S') | ||
| + | '2017-04-10 11:51:17' | ||
| + | >>> datetime.datetime.utcnow() | ||
| + | datetime.datetime(2017, 4, 10, 2, 51, 34, 356682) | ||
| + | >>> datetime.datetime.now() | ||
| + | datetime.datetime(2017, 4, 10, 11, 51, 36, 572681) | ||
| + | >>> datetime.datetime.now().strftime("%A, %d. %B %Y %I:%M%p") | ||
| + | 'Monday, 10. April 2017 11:51AM' | ||
| + | [http://stackoverflow.com/questions/13890935/does-pythons-time-time-return-the-local-or-utc-timestamp] | ||
| + | |||
| + | |||
| + | |||
=={{c|is}} and {{c|<nowiki>==</nowiki>}}== | =={{c|is}} and {{c|<nowiki>==</nowiki>}}== | ||
{{c|is}} is identity testing, {{c|<nowiki>==</nowiki>}} is equality testing. what happens in your code would be emulated in the interpreter like this: | {{c|is}} is identity testing, {{c|<nowiki>==</nowiki>}} is equality testing. what happens in your code would be emulated in the interpreter like this: | ||
2017년 4월 10일 (월) 11:52 판
Time
>>> import time
>>> time.time()
1491792653.410371
>>> import datetime
>>> datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
'2017-04-10 11:51:17'
>>> datetime.datetime.utcnow()
datetime.datetime(2017, 4, 10, 2, 51, 34, 356682)
>>> datetime.datetime.now()
datetime.datetime(2017, 4, 10, 11, 51, 36, 572681)
>>> datetime.datetime.now().strftime("%A, %d. %B %Y %I:%M%p")
'Monday, 10. April 2017 11:51AM'
is and ==
is is identity testing, == is equality testing. what happens in your code would be emulated in the interpreter like this:
>>> a = 'pub' >>> b = ''.join(['p', 'u', 'b']) >>> a == b True >>> a is b False
Access index in for loop
for idx, val in enumerate(ints): print(idx, val)
Max integer
sys.maxint
Argument parsing
use argparse