Re: [Tutor] ASCII characters

2005-05-24 Thread Danny Yoo
On Tue, 24 May 2005, Kent Johnson wrote: > D. Hartley wrote: > > I have a question: what is the "opposite" of hex()? (i.e., like ord > > and chr). If I have > > > > '0x73', how can I get back to 115 or s? > > I don't know a really clean way to do this because '0x73' is not a legal > input value

Re: [Tutor] ASCII characters

2005-05-24 Thread Kent Johnson
D. Hartley wrote: > I have a question: what is the "opposite" of hex()? (i.e., like ord > and chr). If I have > > '0x73', how can I get back to 115 or s? I don't know a really clean way to do this because '0x73' is not a legal input value for int(). The simplest way is to use eval(): >>> eva

Re: [Tutor] ASCII characters

2005-05-24 Thread D. Hartley
I have a question: what is the "opposite" of hex()? (i.e., like ord and chr). If I have '0x73', how can I get back to 115 or s? Thanks! ~Denise > You need the ord() function and maybe hex() also: > >>> ord('s') > 115 > >>> hex(ord('s')) > '0x73' > > Kent > >

Re: [Tutor] ASCII characters

2005-05-24 Thread Kent Johnson
John Carmona wrote: > Thanks Kent for the reply, I am actually having trouble to find the > solution of the following exercise: > > ## Write a for loop that prints the ASCII code of each character in a > string name S.## > > I am ok with the for loop, put I don't know how get to print the ASCII

Re: [Tutor] ASCII characters

2005-05-24 Thread John Carmona
Thanks Kent for the reply, I am actually having trouble to find the solution of the following exercise: ## Write a for loop that prints the ASCII code of each character in a string name S.## I am ok with the for loop, put I don't know how get to print the ASCII code of each character with a st

Re: [Tutor] ASCII characters

2005-05-24 Thread Kent Johnson
John Carmona wrote: > I need to print all the ASCII characters within a string, how would I > delimit for example to print the first 100 only? Many thanks A string is a sequence and supports sequence operations including slices. So s[:100] gives the first 100 chars of a string. You might be i