Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Type Conversion

Tags:

python

types

int

Whats the best way to convert int's, long's, double's to strings and vice versa in python.

I am looping through a list and passing longs to a dict that should be turned into a unicode string.

I do

for n in l:  
    {'my_key':n[0],'my_other_key':n[1]}

Why are some of the most obvious things so complicated?

like image 366
Dave Avatar asked Mar 03 '10 22:03

Dave


1 Answers

To convert from a numeric type to a string:

str(100)

To convert from a string to an int:

int("100")

To convert from a string to a float:

float("100")
like image 87
Mark Byers Avatar answered Oct 23 '22 05:10

Mark Byers