Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #84007 > unrolled thread
| Started by | "Frank Millman" <frank@chagford.com> |
|---|---|
| First post | 2015-01-19 11:26 +0200 |
| Last post | 2015-01-19 11:26 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: How to change the number into the same expression's string and vice versa? "Frank Millman" <frank@chagford.com> - 2015-01-19 11:26 +0200
| From | "Frank Millman" <frank@chagford.com> |
|---|---|
| Date | 2015-01-19 11:26 +0200 |
| Subject | Re: How to change the number into the same expression's string and vice versa? |
| Message-ID | <mailman.17847.1421659596.18130.python-list@python.org> |
"contro opinion" <contropinion@gmail.com> wrote in message
news:CA+YdQ_651X0NDPw1j203WGbeDTxy_Mw7g0w3VH1WoaGR1iv-Cg@mail.gmail.com...
> In the python3 console:
>
> >>> a=18
> >>> b='18'
> >>> str(a) == b
> True
> >>> int(b) == a
> True
>
>
> Now how to change a1,a2,a3 into b1,b2,b3 and vice versa?
> a1=0xf4
> a2=0o36
> a3=011
>
> b1='0xf4'
> b2='0o36'
> b3='011'
>
I am no expert, but does this answer your question ?
C:\>python
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a1 = 0xf4
>>> a1
244
>>> b1 = '0x{:x}'.format(a1)
>>> b1
'0xf4'
>>> int(b1, 16)
244
>>> a2 = 0o36
>>> a2
30
>>> b2 = '0o{:o}'.format(a2)
>>> b2
'0o36'
>>> int(b2, 8)
30
>>> a3 = 011
File "<stdin>", line 1
a3 = 011
^
SyntaxError: invalid token
>>>
Frank Millman
Back to top | Article view | comp.lang.python
csiph-web