Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Datatype Conversion
- Let's see how we can convert datatypes within python!
- We covered how to convert a variable to a string datatype for adding strings,
- but did you know, we can also convert datatypes for general purposes.
- For an example, let's say we have the integer, 1, and we'd want to convert that into "1", and interpret that as a string for any reason.
- We can do that with the syntax of: str(1)
- We can convert it back to an integer using int(1)
- Generally speaking, the syntax is: datatype_name(obj_to_convert)
- We can save this to a variable with: variable_name = str(1), or print it using, print(str(1).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement