COMP 1005 Lecture 12: October 18 2016 /is_in, Range, Splicing

52 views3 pages

Document Summary

October 18 2016 finishing while/for loops, (cid:858)in(cid:859) function. While loops- can iterate until condition is met, can also iterate an exact number of times (using a counter to keep track) For loop- iterate exact number of times over a set of characters, do not need a counter. If we can do something with for loop, can do with while loop. Can sometimes do same thing in for loop as while loop. But there are easier (cid:449)ays to do thi(cid:374)gs: Range for x in range(10) (cid:1005)(cid:1006)(cid:1007)(cid:1008)(cid:1009)(cid:1010) range(stop) range(start,stop) r=range(10) list(r) When we want to know whether a character is in the string or not: use in. In is a boolean def is_in(target,word): index=0 while indexlen(word): return false if len(target)==len(word): return target==word (cid:858)in(cid:859) actually does this for us: (cid:858)a(cid:374)a(cid:374)a(cid:859) i(cid:374) (cid:858)(cid:271)a(cid:374)a(cid:374)as(cid:859) Immutable sequence- cannot change a string (immutable) *but can build a new one based on previous one.

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