Lesson 07: Strings Class Chat: Attendance: Participation

Slides:



Advertisements
Similar presentations
Hand Trace and Output for: int digit = 0; int number = 1423; do { digit = number % 10; System.out.println(digit); number = number / 10; } while (number.
Advertisements

“Everything Else”. Find all substrings We’ve learned how to find the first location of a string in another string with find. What about finding all matches?
Noadswood Science,  To understand what strings are and how decisions are made Thursday, September 17, 2015.
Fundamentals of Python: First Programs
Lesson 4 Using Variables in Python – Creating a Simple ChatBot Program.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 8: Fun with strings.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
Mr. Fowler Computer Science 14 Feb 2011 Strings in Python.
Python Mini-Course University of Oklahoma Department of Psychology Day 3 – Lesson 11 Using strings and sequences 5/02/09 Python Mini-Course: Day 3 – Lesson.
Python – May 16 Recap lab Simple string tokenizing Random numbers Tomorrow: –multidimensional array (list of list) –Exceptions.
Strings, Characters, and Regular Expressions Session 10 Mata kuliah: M0874 – Programming II Tahun: 2010.
Strings … operators Up to now, strings were limited to input and output and rarely used as a variable. A string is a sequence of characters or a sequence.
Last of String Manipulation. Programming Challenge Write a program that asks the user for a string and encodes it by the following guidelines: –If the.
Computer Science 18 Feb 2011 Strings in Python. Introduction Prior experience  Defining string variables  Getting user input  Printing strings Lesson.
GCSE COMPUTER SCIENCE Practical Programming using Python Lesson 4 - Selection.
Lesson 11: Web Services and API's
IST256 : Applications Programming for Information Systems
Lesson 06: Functions Class Participation: Class Chat:
Lesson 12: Data Analysis Class Participation: Class Chat:
Lesson 03: Variables and Types
GCSE COMPUTER SCIENCE Practical Programming using Python
Exam #1 You will have exactly 30 Mins to complete the exam.
Lesson 08: Files Class Participation: Class Chat: Attendance Code 
Lesson 10: Dictionaries Topic: Introduction to Programming, Zybook Ch 9, P4E Ch 9. Slides on website.
Lesson 1 - Sequencing.
Lesson 13: Visualizations
Data Types and Conversions, Input from the Keyboard
Chapter 2 :: Programming Language Syntax
Lesson 02: Introduction to Python
Lesson 1 An Introduction
Lesson 05: Iterations Class Chat: Attendance: Participation
Lesson 07: Strings Topic: Introduction to Programming, Zybook Ch 6, P4E Ch 6. Slides on website.
Strings Part 1 Taken from notes by Dr. Neil Moore
Lesson 12: Data Analysis Topic: Data Analysis, Readings on website.
String Manipulation.
Iterations Programming Condition Controlled Loops (WHILE Loop)
Lesson 13: Visualizations
String Manipulation Part 2
Lesson 04: Conditionals Class Chat: Attendance: Participation
Lesson 05: Iterations Topic: Introduction to Programming, Zybook Ch 4, P4E Ch 5. Slides on website.
CHAPTER THREE Sequences.
Lesson 08: Files Topic: Introduction to Programming, Zybook Ch 7, P4E Ch 7. Slides on website.
Lesson 09: Lists Topic: Introduction to Programming, Zybook Ch 8, P4E Ch 8. Slides on website.
4. sequence data type Rocky K. C. Chang 16 September 2018
IST256 : Applications Programming for Information Systems
Lesson 06: Functions Class Chat: Attendance: Participation
CEV208 Computer Programming
String and Lists Dr. José M. Reyes Álamo.
Variables and Expressions
Coding Concepts (Data- Types)
Lesson 09: Lists Class Chat: Attendance: Participation
Lesson 03: Variables and Types
Lesson 08: Files Class Chat: Attendance: Participation
Lesson 11: Web Services and API's
Suppose I want to add all the even integers from 1 to 100 (inclusive)
Fundamentals of Python: First Programs
Lesson 10: Dictionaries Class Chat: Attendance: Participation
CS1110 Today: collections.
7 – Variables, Input and Output
Introduction to Computer Science
Lesson 12: Data Analysis Class Chat: Attendance: Participation
IST256 : Applications Programming for Information Systems
“Everything Else”.
Lesson 02: Introduction to Python
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
Lesson 07: Strings Class Chat: Attendance: Participation
More Basics of Python Common types of data we will work with
Strings Taken from notes by Dr. Neil Moore & Dr. Debby Keen
IST256 : Applications Programming for Information Systems
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Lesson 07: Strings Class Chat: Attendance: Participation Link: In Gitter.im | Code: ???? Class Chat: https://gitter.im/IST256/Fudge Participation http://ist256.participoll.com/

Questions? Ask in Our Course Chat! Agenda Strings are immutable sequence of characters. Index and Slice notation for retrieving sub-strings. Built-in string functions to perform operations on strings. Techniques for parsing and tokenizing string data. How to sanitize input with string functions. You’ve Read: Zybook Ch6 P4E Ch6 https://gitter.im/IST256/Fudge Questions? Ask in Our Course Chat!

TANGENT RANT: Code is for People, too! Both of these code samples are the same, but which of these is easier for a human to read? A. Top One B. Bottom One A B

Connect Activity To get a substring from an existing Python string we use? A built in function Slice notation A B

Strings are Sequences of Characters Strings are index able sequences of characters. The characters inside the string are immutable. Example: Name = ‘Fudge’ len(Name) == 5 Immutable means we can’t change part of it: Name[1] = ‘u’

Slice Notation Name[0:2] == 'Fu' Name[2:5] == 'dge' Name[:4] == 'Fudg' Slice Notation is used to extract a substring. Examples: Name[0:2] == 'Fu' Name[2:5] == 'dge' Name[:4] == 'Fudg' Name[:] == 'Fudge' Name[1:-1] == 'udg

Check Yourself: String Slices 1 Match each string slice to its value for this string: x ='orange' x[1:6] x[2:-1] x[1:] 'ang' 'rang' 'range' A B C

Check Yourself: String Slices 2 Match each string slice to its value for this string: x ='orange' x[1:6] x[2:-1] x[1:] 'ang' 'rang' 'range' A B C

String functions: Built In String Functions: https://docs.python.org/3/library/stdtypes.html#text- sequence-type-str dir(str) help(str.upper) The Python String Library: https://docs.python.org/3/library/string.html You must import String before you can use them.

Watch Me Code 1 Yes or No? write a function to accept a variety of inputs as "yes" or "no" "yes"  "y", "Y", "YES", "Yes" etc… "no"  "n", "N", "NO", "No", etc…

Check Yourself: Code Trace 1 What is the value of the variable y on line 2? 'Miie' 'MKKE' 'MIIE' 'Mkke' A B C D

String Tokenization and Parsing Tokenization is the process of breaking up a string into words, phrases, or symbols. Tokenize a sentence into words. "mike is here"  ['mike','is','here'] Parsing is the process of extracting meaning from a string. Parse text to a numerical value or date. int('45')  45

Watch Me Code 2 Given a string of digits: e.g. '12 45 90' Tokenize into individual strings Parse into integers Add them up!

Check Yourself: Code Trace 2 What is the output of this program? This T Tim mike A B C D

End-To-End Example Write a function percentage() to input a percentage. 0.3 == 0.3 30% == 0.3 String parsing, finding '%'

Conclusion Activity "1 Question Challenge" x[4:8] What is the value of: x[4:8] When x = 'Syracuse'?