CSCI 1301 Lecture Notes - Lecture 2: Type Conversion, Empty String, 5,6,7,8

32 views4 pages

Document Summary

To change an integer or float to a string, use str(number) To change a string or float into an integer, use int(string/float) To change an integer or string into a float, use float(number) Trace this function: what does each print line show? def mathwithstrings(): string1 = "what are you doing?" string2 = "horizontal running" print string1 + string2 print string1 * 3 print string1 * string2 print string1 + 7. Here are examples of how to concatenate strings together: "this is " + "cs 1315" "this is cs 1315" string1 = "cats are " string2 = "cool" string1 + string2 "cats are cool" You must cast all variables to the same data type. >>> print "the lazy brown dog jumped " + str(7) + " times!" >>> print "the lazy brown dog jumped", 7, "times!" If you need to iterate over a sequence of numbers, range() allows you to create a list of numbers. i. e. range(10) = [0,1,2,3,4,5,6,7,8,9]

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