Difference between revisions of "Conversions - Python"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "=Data Type Conversions= Python has built in functions to convert between different data types. To convert something to an integer you would enter: <syntaxhiglight lang=pytho...")
 
Line 3: Line 3:
 
Python has built in functions to convert between different data types. To convert something to an integer you would enter:
 
Python has built in functions to convert between different data types. To convert something to an integer you would enter:
  
<syntaxhiglight lang=python>
+
<syntaxhighlight lang=python>
 
number = int( textEntered)
 
number = int( textEntered)
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 9: Line 9:
 
or if you wanted to get the input direct from the user you could do this instead:
 
or if you wanted to get the input direct from the user you could do this instead:
  
<syntaxhiglight lang=python>
+
<syntaxhighlight lang=python>
 
name = int( input(“enter a number”) )
 
name = int( input(“enter a number”) )
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 09:23, 20 June 2018

Data Type Conversions

Python has built in functions to convert between different data types. To convert something to an integer you would enter:

number = int( textEntered)

or if you wanted to get the input direct from the user you could do this instead:

name = int( input(enter a number) )

Other conversion functions are available:

Conversions in python.png