Fatal Rein Fatal Rein - 1 year ago 127
Python Question

converting chr() / ord() with multi characters

beginner programming in python (3.4)

is it possible to pass multiple values inside chr() and ord()?
what i tried is the following:

userInput = input('Please write your input: ')
> Hello
result = ord(userInput) #here is the error because i put multiple values instead of just one

this is the output i am looking for:
72 101 108 108 111
(hello) but instead i get an error telling me i can only pass 1 character/value inside chr() / ord()
is this possible? if not can you provide me in the right direction? thank you

Answer Source

Use a list comprehension - apply ord to each character in the string.

In [777]: [ord(i) for i in 'hello']
Out[777]: [104, 101, 108, 108, 111]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download