# Tuples similar to list but form using parenthesis

• Notes
• 27

This preview shows pages 23–27. Sign up to view the full content.

Tuples Similar to list, but form using parenthesis Immutable, major difference compare with list Non-mutable operations in list can apply to tuple >>> tup = (1,7,3,1,7,3) >>> 3 in tup True >>> list(tup) [1, 7, 3, 1, 7, 3] >>> tuple(['a', 'b', 'c']) ('a', 'b', 'c') CSCI2040 Introduction to Python 23

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

Tuples Comma operator implicitly creates a tuple >>> 'a','b','c‘ ('a', 'b', 'c') Application in function returning more than 1 result def minAndMax( info ): return (min(info), max(info)) >>> x, y = minAndMax( 'abcd') >>> x 'a‘ >>> y 'd' CSCI2040 Introduction to Python 24
What good list & strings brings? Consider the following problem: Write a program to check whether an input string is a strong password, which has to contain 1. lower case letters, 2.upper case letters, 3. digits, 4. special characters, and 5. the length has to be no shorter than 12. We would do this by testing one by one CSCI2040 Introduction to Python 25

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

What good list & strings brings? In C language, we would proceed to test the ASCII code of input string character by character char pw[100]; int cnt=0; scanf(“%s”, pw); for (i=0; i<strlen(pw); i++) if (islower(pw[i]) cnt++; if (cnt<=0) printf(“No lower case “); Need to think of character, loop , character function Many low level thinking CSCI2040 Introduction to Python 26
What good list & strings brings? In Python, the thinking is different lowercase='abcdefghijklmnopqrstuvwxyz‘ for c in password: has_lowercase = has_lowercase or (c in lowercase) if not has_lowercase: print('No lowercase ') CSCI2040 Introduction to Python 27
This is the end of the preview. Sign up to access the rest of the document.
• Fall '17
• Letter case, Lower case

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern