CPSC 319 Lecture 6: CPSC 231 - Type Conversion

44 views1 pages

Document Summary

Boolean: a boolean is either true or false. Float: similar to an integer, but has decimal places. String: a string is any value within a set of quotation marks. For example, 5 is a string value, and is not the same as 5, which is an integer. Explicit: direct transforming of one value to another, using the operators. Type conversion str() converts any value to a string str(54) (cid:3247)54(cid:3248) int() converts values into integers. Be careful with this, as attempting to convert something like hello to an integer will result in errors. Floats that are converted to integers are not rounded, the decimal is simply dropped. int((cid:3247)34(cid:3248)) 34 int((cid:3247)test(cid:3248)) error int(3. 65) 3 float() converts values to a number with decimal values. Be wary of converting strings, as this may result in errors. Integers that are converted to floats will now have a decimal value. float((cid:3247)5(cid:3248)) 5. 0 float((cid:3247)this is a string(cid:3248)) error float(6) 6. 0.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents