1
x = (input("month: "), input("day: "), input("Year: "))

month: 11 day: 1 Year: 2016 ('11', '11', '2016') <---- how can I convert this in to this 11/01/2016 format?

1
  • There are mainly two ways to go. You could use "/".join(x) to connect the tuple to one string, or you could feed the month/day/year into Python's datetime library. Commented Oct 18, 2017 at 14:04

1 Answer 1

1

You don't need the functionalities of the datetime module, you can simply go:

>>> x = input("month: ") + '/' + input("day: ") + '/' + input("year: ")
month: 11
day: 01
year: 2016
>>> x
'11/01/2016'

If you want to make it look pretty and pythonic:

>>> x = "%s/%s/%s" % (input("month: "), input("day: "), input("year: "))
month: 11
day: 01
year: 2016
>>> x
'11/01/2016'

Datetime won't help you here, as it's formatting applies mostly to time math.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.