Strings The Basics. Strings a collection data type can refer to a string variable as one variable or as many different components (characters) string.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Introduction to C Programming
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Python Basics: Statements Expressions Loops Strings Functions.
Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
Current Assignments Homework 5 will be available tomorrow and is due on Sunday. Arrays and Pointers Project 2 due tonight by midnight. Exam 2 on Monday.
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.
Characters and Strings. Characters In Java, a char is a primitive type that can hold one single character A character can be: –A letter or digit –A punctuation.
Computer Science 111 Fundamentals of Programming I Sequences: Strings.
FOR DOWNTO Suppose you want to write a FOR-DO loop where the control variable is decreased with each repetition of the loop. Pascal provides the reserved.
Section 2 - More Basics. The char Data Type Data type of a single character Example char letter; letter = 'C';
Noadswood Science,  To understand what strings are and how decisions are made Thursday, September 17, 2015.
October 4, 2005ICP: Chapter 4: For Loops, Strings, and Tuples 1 Introduction to Computer Programming Chapter 4: For Loops, Strings, and Tuples Michael.
Lists in Python.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 More About Strings.
Strings The Basics. Strings can refer to a string variable as one variable or as many different components (characters) string values are delimited by.
Fall 2002CMSC Discrete Structures1 … and now for… Sequences.
Fundamentals of Python: First Programs
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 8: Fun with strings.
Introduction to Strings Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Mr. Fowler Computer Science 14 Feb 2011 Strings in Python.
 How do you represent a number with no value?  Mathematicians defined the “number” 0 (zero)  How do we represent a string with no value?  Use an empty.
Python – May 12 Recap lab Chapter 2 –operators –Strings –Lists –Control structures.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
CECS 5020 Computers in Education Visual Basic Variables and Constants.
5 February 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions.
3/16/20161 … and now for… Sequences. 3/16/20162 Sequences Sequences represent ordered lists of elements. A sequence is defined as a function from a subset.
17-Mar-16 Characters and Strings. 2 Characters In Java, a char is a primitive type that can hold one single character A character can be: A letter or.
Strings CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1.
More String Manipulation. Programming Challenge Define a function that accepts two arguments: a string literal and a single character. Have the function.
Strings CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
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.
Windows Programming Lecture 03. Pointers and Arrays.
Introduction to Programming
String and Lists Dr. José M. Reyes Álamo.
Tuples and Lists.
Lists Part 1 Taken from notes by Dr. Neil Moore & Dr. Debby Keen
Lecture 4 Using Classes Richard Gesick.
Winter 2018 CISC101 11/16/2018 CISC101 Reminders
Visual Basic .NET BASICS
Introduction to Strings
Introduction to Strings
Lists in Python.
Using files Taken from notes by Dr. Neil Moore
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
T. Jumana Abu Shmais – AOU - Riyadh
Comparing Strings – How to
String and Lists Dr. José M. Reyes Álamo.
Rocky K. C. Chang September 18, 2018 (Based on Zelle and Dierbach)
Introduction to Strings
CHAPTER 3: String And Numeric Data In Python
functions: argument, return value
15-110: Principles of Computing
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Topics Basic String Operations String Slicing
String Processing 1 MIS 3406 Department of MIS Fox School of Business
Introduction to Computer Science
Introduction to Strings
Sequences Sequences are collections of data values that are ordered by position A string is a sequence of characters A list is a sequence of any Python.
Topics Basic String Operations String Slicing
By Himanshi dixit 11th ’B’
Class code for pythonroom.com cchsp2cs
Introduction to Strings
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Topics Basic String Operations String Slicing
Introduction to Computer Science
Presentation transcript:

Strings The Basics

Strings a collection data type can refer to a string variable as one variable or as many different components (characters) string values are delimited by either single quotes or double quotes operators + and * (overloaded operators) + “concatenation” sticks two strings together to get a new string * “replication” repeats a string a given number of times to give a new string precedence is * above + order of concatenation matters! “a” + “b” is not the same as “b” + “a”

Indexing Also called subscripts A way to tell individual characters of a string apart notation like that used for lists [ ] with an integer (constant or variable) inside Strings are numbered from 0 on left end and increasing Strings are also numbered from -1 on right end and decreasing You can use an expression as an index also, like str[k + 1], as long as the expression has an integer value

The len function Note this is a function, not a method (do not call it with the dot notation) len operates on one argument, either a string or a list returns an integer result, tells how many characters are in the string or how many elements are in the list lowest return value is zero for the empty string Python claims “no upper limit on string length”, literally it depends on your environment – how much RAM you have, which OS you are running, on a typical PC today with Windows it is around 2 billion characters s[len(s)] would give an error! Remember that len tells you how many characters, not what the last subscript in the string would be

chr and ord functions Sometimes you need to work with the ASCII codes of individual characters chr(integer) will return the character corresponding to the ASCII code argument, example chr(65) will return “A” ord(char) will return the ASCII code (as an integer) of the single character that you send, example ord(“A”) will return 65 In general, use the characters instead of their ASCII values in coding, it will be much more obvious what you are doing Do NOT say “if ch >= 65 and ch <= 90” when you are checking for upper case it is MUCH better to say if ch >= “A” and ch <=“Z” or even if ch in ascii_uppercase or if ch.isupper()

The slice operator The “substring” operator in Python See separate set of slides