1

I'm learning the python's datetime module, and found two useful functions: datetime.strptime() and datetime.strftime().

I know that the functions meaning, datetime.strftime() could convert a time object to a specified format string, I could understand the strftime as "string from time", the "f" means "from". But what's the meaning of the "p" in strptime()? I understand it's a function as "convert a string to a time object", so it should be strttime() instead of strptime().

Who else also feel confused on this function name? Thanks in advance no matter you could answer this question or share the same confusion with me.

martineau
  • 119,623
  • 25
  • 170
  • 301
Clock ZHONG
  • 875
  • 9
  • 23
  • The `p` stands for "parse". Practically, it **parses** the `string` into a `datetime` object. – Tiberiu Zulean Nov 13 '18 at 09:43
  • The "f" in strftime actually comes from "format". – chthonicdaemon Nov 13 '18 at 09:56
  • This question is really asked by others. And let me list the possible answers here: 1. Pointer(time object pointer), 2. Parser(String's parser to a time object), 3. Posix(return a posix time object), 4. Put( put a string represented time to a time object) – Clock ZHONG Nov 14 '18 at 01:14

1 Answers1

1

These are the developer doc string says. I guess p stands for parsing datetime from a string type.

In [2]: datetime.datetime.strptime??
Docstring: string, format -> new datetime parsed from a string (like time.strptime()).
Type:      builtin_function_or_method

In [3]: datetime.datetime.strftime??
Docstring: format -> strftime() style string.
Type:      method_descriptor
Tiberiu Zulean
  • 162
  • 3
  • 13
Rahul K P
  • 15,740
  • 4
  • 35
  • 52