For example, i = { 'Hong Gil-dong' : 20 years old'}
When it comes to print(i)
, it's {'Hong Gil-dong': 20 years old'
It comes out like this
'Hong Gil-dong': 20 years old
Like this
Hong Gil-dong: 20 years old
Is there a way to make it look this neat?
>>> s = "%s"%(i)
>>> s
"{'Hong Gil-dong': 20 years old'}"
>>> s[1:-1]
"Hong Gil Dong: 20 years old"
>>> "%s"%(i)[1:-1]
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
"%s"%(i)[1:-1]
TypeError: unhashable type: 'slice'
>>> ("%s"%(i))[1:-1]
"Hong Gil Dong: 20 years old"
>>> print(("%s"%(i))[1:-1])
'Hong Gil-dong': "20 years old"
>>> for e in i.items(): print(e)
("Hong Gil-dong, Hong Gil-dong
>>> for e in i.items(): print(*e)
Hong Gildong is 20 years old
>>> for e in i.items(): print(':'.join(e))
Hong Gil-dong: 20 years old
© 2024 OneMinuteCode. All rights reserved.