Difference between revisions of "Python:Convert a String to a Number"

From Progzoo
Jump to: navigation, search
(New page: ==String to int== <question xmlns:htm="http://www.w3.org/1999/xhtml" lang="py" className="Demo"><prog> s = "1234" i = int(s) print i+1 </prog> <p>You can use the functions <code>int</code>...)
 
 
Line 1: Line 1:
==String to int==
+
{{topTenTips}}
 
<question xmlns:htm="http://www.w3.org/1999/xhtml" lang="py" className="Demo"><prog>
 
<question xmlns:htm="http://www.w3.org/1999/xhtml" lang="py" className="Demo"><prog>
 
s = "1234"
 
s = "1234"

Latest revision as of 21:19, 31 December 2007

You can use the functions int and float to convert to integers or floating point numbers.

The value "1234" is a string, you need to treat it as a number - to add 1, giving 1235.

[Font] [Default] [Show] [Resize] [History] [Profile]