Skip to content

Instantly share code, notes, and snippets.

@nasturtus
Created April 17, 2017 04:37
Show Gist options
  • Save nasturtus/150ef873826b1578c21ebc65af784f27 to your computer and use it in GitHub Desktop.
Save nasturtus/150ef873826b1578c21ebc65af784f27 to your computer and use it in GitHub Desktop.
# The goal of str() is readbility.
# The goal of repr() is to be unambiguous.
# The goal of type() is, well..to display the type.
# Reference: Corey Schafer https://www.youtube.com/watch?v=5cvM-crlDvg
from datetime import datetime
a = datetime.now()
print(str(a))
print(repr(a)) # shows unambiguously it's a datetime
print()
b = str(a)
print(b)
print(repr(b)) # single quotes indicate unambiguously it's a string
print()
print(type(a))
print(type(b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment