sonicsword
sonicsword

Reputation: 21

Print words using string module and ascii in python?

I was curious about how ASCII worked in python, so I decided to find out more. I learnt quite a bit, before I began to try to print letters using ASCII numbers. I'm not sure if I am doing it correctly, as I am using the string module, but I keep picking up an error

print(string.ascii_lowercase(104))

This should print out "h", as far as I know, but all that happens is that I receive an error.

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    string.ascii_lowercase(104)
TypeError: 'str' object is not callable

If someone could help me solve this, or tell me a better way, I would be ever grateful. Thanks in advance! :)

Upvotes: 1

Views: 212

Answers (3)

user5597655
user5597655

Reputation:

The chr() function returns the corresponding character to the ASCII value you put in.

The ord() function returns the ASCII value of the character you put in.

Example:

chr(104) = 'h'
ord('h') = 104

Upvotes: 1

Aaron
Aaron

Reputation: 2393

I guess what you want is chr

>>> chr(104)
'h'

Upvotes: 2

Mark Tolonen
Mark Tolonen

Reputation: 178021

ascii_lowercase is a string, not a function. Use chr(104).

Upvotes: 4

Related Questions