python11.html - CHAPTER 11 tuples these are both tuples t1...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CHAPTER 11 tuples these are both tuples: t1 = ("apple", "orange") t2 = "banana", "cherry" t1 = ("apple", 3, 1.4) #different types t2 = ("apple", 3, 1.4, ("banana", 5)) #tuples within tuples tuple and lists (next chapter) support the use of the operators + and *. These operators work similar as to how they work for strings. #example00.py t1 = (1,2) t2 = (3,4) t3 = t1 + t2 print(t3) #(1, 2, 3, 4) t4 = 10*(5,6) print(t4) #(5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6) #example01.py: print the elements of a tuple def printTuple(tt): print("print members of tuple: ",tt) for x in tt: print(x) print("===============================") printTuple('apple', 3, 1.4, ('banana', 5)) previous code prints: print members of tuple: ('apple', 3, 1.4, ('banana', 5)) apple 3 1.4 ('banana', 5) example02.py: exercise: write a version of printTuple that prints out elements of tuples within tuples. Try to at least describe the logic of the new printTuple Example: tuple: ('apple', 3, 1.4, ('banana', 5)) =============================oldPrintTuple: apple 3 1.4 ('banana', 5) =============================printTuple: apple 3 1.4
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
banana 5 example03.py: can you write the following version of printTuple?
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern