IT/Python: Codecademy

Python 2 Strings and Console Output

Last72 2018. 2. 18. 17:22

Three ways to create strings

'Alpha' "Bravo" str(3)

String methods

len("Charlie") "Delta".upper() "Echo".lower()

Printing a string

print "Foxtrot"

Advanced printing techniques

g = "Golf" h = "Hotel" print "%s, %s" % (g, h)


Date and time

from datetime import datetime
now = datetime.now()

print '%s/%s/%s %s:%s:%s' % (now.month, now.day, now.year, now.hour, now.minute, now.second)