Skip to content

Instantly share code, notes, and snippets.

@Robofied
Created February 10, 2019 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Robofied/c8b742040a0b753f97ba15b3d5a15809 to your computer and use it in GitHub Desktop.
Save Robofied/c8b742040a0b753f97ba15b3d5a15809 to your computer and use it in GitHub Desktop.
Intermediate Python
## Creating a string variable
b = 'Learn!'
## In this string value case str is giving output without '' but repr is giving output with ''
print(str(b))
#[Output]:
#Learn!
## In this string value case str is giving output without '' but repr is giving output with ''
print(repr(b))
#[Output]:
#'Learn!'
## Importing date and time module to get today's date and recent time.
import datetime
## Printing the value using str() function then it gives simply a value
print(str(datetime.datetime.now()))
#[Output]:
#2018-11-14 15:26:04.980581
## Printing the value using repr() function then it is giving the type of object.
## Generally used for debugging mode by developers.
print(repr(datetime.datetime.now()))
#[Output]:
#datetime.datetime(2018, 11, 14, 15, 26, 15, 325797)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment