Doodoongsil
Doodoongsil

Reputation: 13

How to change character to ASCII in python without ord()

I know the function 'ord' can convert character to number. but I just want to know how to convert without 'ord'

C can convert it, but is it impossible in Python ?

Upvotes: 0

Views: 1888

Answers (2)

Siam Mahamud
Siam Mahamud

Reputation: 1

You can use len() function to solve it input("any value?") print(len("value"))input("any value you want") print(len("enter your value"))

Upvotes: -1

CryptoFool
CryptoFool

Reputation: 23119

You can encode a string as bytes, at which point you can access the representation of each character. So you can do this:

print("a".encode()[0])
print("3".encode()[0])
print("#".encode()[0])

Result:

97
51
35

Upvotes: 4

Related Questions