lock_sh 示例_带有示例的Python date __str __()方法
lock_sh 示例
Python date .__ str __()方法 (Python date.__str__() Method)
date.__str__() method is used to manipulate objects of date class of module datetime.
date .__ str __()方法用于操作模塊datetime的date類的對象。
It uses a date class object and returns a string representation of the object. For a date object d, str(d) is equivalent to d.isoformat(). str() is an instance method as it uses an instance of the class.
它使用日期類對象,并返回該對象的字符串表示形式。 對于日期對象d , str(d)等效于d.isoformat() 。 str()是一個實例方法,因為它使用類的實例。
Module:
模塊:
import datetimeClass:
類:
from datetime import dateSyntax:
句法:
str()Return value:
返回值:
The return type of this method is a string representing the original date.
此方法的返回類型是代表原始日期的字符串。
Example:
例:
## importing date class from datetime import date## Creating an instance x = date.today() d = str(x) print("Original object:",x) print("Date String:", d) print()## str function also uses the ISO format x = date(2020,10,1) print("Date string of date 2020/10/1:", str(x)) print()## str(x) is equivalent to x.isoformat() function x = date(200,10,12) print("Date 200/10/12 in ISO 8601 format using isoformat() function:", x.isoformat()) print("Date string 200/10/12 using str() function:", str(x)) print( x.isoformat() == str(x))Output
輸出量
Original object: 2020-04-29 Date String: 2020-04-29Date string of date 2020/10/1: 2020-10-01Date 200/10/12 in ISO 8601 format using isoformat() function: 0200-10-12 Date string 200/10/12 using str() function: 0200-10-12 True翻譯自: https://www.includehelp.com/python/date-__str__-method-with-example.aspx
lock_sh 示例
總結
以上是生活随笔為你收集整理的lock_sh 示例_带有示例的Python date __str __()方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 鼻部整形的多少钱啊?
- 下一篇: 在Python中以二进制格式输入数字