AOIT Introduction to Programming Unit 3, Lesson 10 Advanced Sequence Manipulation Copyright © 2009–2012 National Academy Foundation. All rights reserved.

Slides:



Advertisements
Similar presentations
Course A201: Introduction to Programming 10/28/2010.
Advertisements

String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
An Introduction to Programming with C++ Fifth Edition Chapter 12 String Manipulation.
Introduction to Python
Guide to Programming with Python Chapter Two Basic data types, Variables, and Simple I/O: The Useless Trivia Program.
1.
An Introduction to Textual Programming
Bell Ringer What types are numbers are there is the python programming language?
Noadswood Science,  To understand what strings are and how decisions are made Thursday, September 17, 2015.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 More About Strings.
CATHERINE AND ANNIE Python: Part 4. Strings  Strings are interesting creatures. Although words are strings, anything contained within a set of quotes.
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved.1 Chapter 4 Mathematical Functions, Characters, and Strings.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.
12/9/2010 Course A201: Introduction to Programming.
Operations on Strings. 8/8/2005 Copyright 2006, by the authors of these slides, and Ateneo de Manila University. All rights reserved L: String Manipulation.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 8 Lists and Tuples.
Project 1: Using Arrays and Manipulating Strings Essentials for Design JavaScript Level Two Michael Brooks.
Chapter 5 Strings CSC1310 Fall Strings Stringordered storesrepresents String is an ordered collection of characters that stores and represents text-based.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 3 Mathematical Functions, Strings, and Objects.
CS105 STRING LIST TUPLE DICTIONARY. Characteristics of Sequence What is sequence data type? It stores several objects Each object has an order Each object.
More Strings CS303E: Elements of Computers and Programming.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Introduction to Strings CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Basic Variables & Operators Web Programming1. Review: Perl Basics Syntax ► Comments: start with # (ignored by Perl) ► Statements: ends with ; (performed.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
17-Feb-16 String and StringBuilder Part I: String.
LISTS and TUPLES. Topics Sequences Introduction to Lists List Slicing Finding Items in Lists with the in Operator List Methods and Useful Built-in Functions.
8 1 String Manipulation CGI/Perl Programming By Diane Zak.
Last of String Manipulation. Programming Challenge: Usernames Let’s say you work at the IT department for NYU and you are asked to generate student ID’s.
AOIT Introduction to Programming Unit 3, Lesson 9 Sequences—Lists and Tuples Copyright © 2009–2012 National Academy Foundation. All rights reserved.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions.
Strings CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1.
Strings CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1.
LECTURE 5 Strings. STRINGS We’ve already introduced the string data type a few lectures ago. Strings are subtypes of the sequence data type. Strings are.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 this week – last section on Friday. Assignment 4 is posted. Data mining: –Designing functions.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki.
String and Lists Dr. José M. Reyes Álamo.
String Methods Programming Guides.
String Processing Upsorn Praphamontripong CS 1110
Variables and Primative Types
Introduction to Scripting
Strings Part 1 Taken from notes by Dr. Neil Moore
Microsoft Visual Basic 2005 BASICS
Engineering Innovation Center
String and StringBuilder
Winter 2018 CISC101 11/16/2018 CISC101 Reminders
String Manipulation Part 2
String and StringBuilder
Microsoft Visual Basic 2005 BASICS
“If you can’t write it down in English, you can’t code it.”
CSC 221: Introduction to Programming Fall 2018
String and Lists Dr. José M. Reyes Álamo.
Topics Sequences Introduction to Lists List Slicing
Basic String Operations
String and StringBuilder
CS 1111 Introduction to Programming Spring 2019
Topics Basic String Operations String Slicing
Introduction to Computer Science
String methods 26-Apr-19.
Topics Sequences Introduction to Lists List Slicing
Python Strings.
Topics Basic String Operations String Slicing
Strings Taken from notes by Dr. Neil Moore & Dr. Debby Keen
Topics Basic String Operations String Slicing
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

AOIT Introduction to Programming Unit 3, Lesson 10 Advanced Sequence Manipulation Copyright © 2009–2012 National Academy Foundation. All rights reserved.

Methods and functions make sequences more powerful Examples: String methods can test strings: "abCde".isalpha() returns True String methods can change strings: "abCde".lower() returns "abcde" List and tuple functions can return information: Given mytuple = ("horse","cow","sheep") len(mytuple) returns 3 If you applied the len() function to the suit_string tuple in the Shuffle Cards program, what would you get?

String-testing methods test to see whether a string has a certain form Prior Program: New Password New Program: Hangman Key Characteristics: Returns True or False Examples: string.isalnum() string.isalpha() string.isnumeric() # string contains only letters or numbers # string contains only letters # string contains only numbers What do you suppose string.islower() does?

Case-changing methods change the case of a string Prior Programs: Menu and Vacation New Program: Hangman Key Characteristics: Operates on (makes a change in) a string Examples: string.capitalize() string.lower() string.upper() # capitalize the first character # convert to lowercase # convert to uppercase What do you suppose string.swapcase() does?

String-formatting methods format string (text) output Prior Program: Menu New Program: Hangman Key Characteristics: Formats printed output Examples: string.center(width) string.ljust(width) You will use these methods in the text art for Hangman. # center string within a given width # left-justify string What is the method to right-justify? What does right-justify mean?

Escape sequences are useful in formatting text Note: sequence here means “a string of characters” Backslashes (\) are used in Python programs to insert special characters into strings. An example you have seen before (in the Menu and Vacation programs) is \t, which moves the cursor forward one tab stop. Another example is \", which prints a double quote. You might find escape sequences useful in the text art for Hangman. What is the escape sequence to print a single quote?

find() is the most useful string-searching method The find() method finds the first occurrence of a substring in a string. find() returns the lowest index where the substring is found, and it returns -1 if it is not found. The format is string.find(substring). An example is "abcd".find("a"), which returns 0. What do you think "abcd".find("c") returns? What do you think "abcd".find("e") returns?

The string-stripping and string-replacement methods change strings Prior Program: Vacation New Program: Hangman Key Characteristics: Makes changes to strings Examples: "cat".replace("t","b") returns 'cab' " 12A B ".strip() returns '12A B' String-stripping is used in Hangman. What do you think "Happy Birthday! ".strip() returns?

Hangman uses several list and tuple methods and functions Prior Program: Shuffle Cards New Program: Hangman Names: append(), pop(), join(), and len() Examples (from Shuffle Cards): cards.append(card_string) return deck.pop(0) How would you return the last card in the deck? # append each card string in turn # to the end of the list of cards # return the first card in the deck # to the calling function # and remove it from the list

Hangman uses several list and tuple methods and functions (continued) Examples (from Hangman): print(''.join(guesses)) word_len = len(theword) If the word is antelope, what value is assigned to word_len? # print the letters correctly guessed # if the word is hyena and the player has guessed a # then join() returns '_ _ _ _a' (four underscores and an a) # assign the length of the word # to the variable word_len

Methods and functions are used extensively with sequences You have used many methods and functions in prior programs. You will be using a number of methods and functions in the Hangman minor project and in your culminating project. It is helpful to categorize methods and functions based on what they do and on what kind of sequences they work with. For more information about methods and functions, see the course’s QuickStart Guide.