Sep 17, 2019

python str vs repr vs eval

import datetime 

foo = 100
var = 'foo'

print(var) #foo

#with quotes
print(repr(var)) #'foo'

#evaluates any variables
print(eval(var)) #100

today = datetime.datetime.now()

# Prints readable format for date-time object
print (str(today)) #2019-09-17 11:54:13.675979

# prints the official format of date-time object
print (repr(today)) #datetime.datetime(2019, 9, 17, 11, 54, 13, 675979)

No comments:

Post a Comment