Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. Datatype Conversion
  2.  
  3. Let's see how we can convert datatypes within python!
  4.  
  5. We covered how to convert a variable to a string datatype for adding strings,
  6. but did you know, we can also convert datatypes for general purposes.
  7.  
  8. 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.
  9.  
  10. We can do that with the syntax of: str(1)
  11. We can convert it back to an integer using int(1)
  12.  
  13. Generally speaking, the syntax is: datatype_name(obj_to_convert)
  14.  
  15. 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