Strings.

Slides:



Advertisements
Similar presentations
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.
Advertisements

03 Data types1June Data types CE : Fundamental Programming Techniques.
Introduction to Python
Computing with Strings CSC 161: The Art of Programming Prof. Henry Kautz 9/16/2009.
Python Control of Flow.
***** SWTJC STEM ***** Chapter 2-2 cg Identifiers - Naming Identifier, the name of a Java programming component. Identifier naming rules... Must.
Python for Informatics: Exploring Information
Python Mini-Course University of Oklahoma Department of Psychology Day 3 – Lesson 12 More about strings 05/02/09 Python Mini-Course: Day 3 – Lesson 12.
Programming in Python Part III Dr. Fatma Cemile Serçe Atılım University
Strings CS303E: Elements of Computers and Programming.
Functions Chapter 4 Python for Informatics: Exploring Information
Characters. Character Data char data type – Represents one character – char literals indicated with ' '
Looping and Counting Lecture 3 Hartmut Kaiser
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
Chapter 5 Strings CSC1310 Fall Strings Stringordered storesrepresents String is an ordered collection of characters that stores and represents text-based.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 8: Fun with strings.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Decision Structures, String Comparison, Nested Structures
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
By Austin Laudenslager AN INTRODUCTION TO 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.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Midterm Review Important control structures Functions Loops Conditionals Important things to review Binary Boolean operators (and, or, not) Libraries (import.
Variables, Types, Expressions Intro2CS – week 1b 1.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
Functions Chapter 4 Python for Informatics: Exploring Information Slightly modified by Recep Kaya Göktaş on March 2015.
What is Binary Code? Computers use a special code of their own to express the digital information they process. It's called the binary code because it.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Python Strings. String  A String is a sequence of characters  Access characters one at a time with a bracket operator and an offset index >>> fruit.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions.
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.
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.
Input, Output and Variables GCSE Computer Science – Python.
Chapter 4 Computing With Strings Charles Severance Textbook: Python Programming: An Introduction to Computer Science, John Zelle.
ENGINEERING 1D04 Tutorial 2. What we’re doing today More on Strings String input Strings as lists String indexing Slice Concatenation and Repetition len()
The Methods and What You Need to Know for the AP Exam
GCSE COMPUTER SCIENCE Practical Programming using Python
Python Basics.
String and Lists Dr. José M. Reyes Álamo.
G. Pullaiah College of Engineering and Technology
Whatcha doin'? Aims: To start using Python. To understand loops.
Strings Chapter 6 Python for Everybody
Input and Output Upsorn Praphamontripong CS 1110
Introduction to Python
Tuples and Lists.
Chapter 4 Computing With Strings
Lecture 5 Strings.
Week 3: Loops and strings
String Manipulation.
Strings Chapter 6 Slightly modified by Recep Kaya Göktaş in April Python for Informatics: Exploring Information
Decision Structures, String Comparison, Nested Structures
Basic Python Collective variables (sequences) Lists (arrays)
Introduction to Python
Decision Structures, String Comparison, Nested Structures
An Introduction to Java – Part I, language basics
Python - Strings.
Python for Informatics: Exploring Information
CEV208 Computer Programming
String and Lists Dr. José M. Reyes Álamo.
Python for Informatics: Exploring Information
CS1110 Today: collections.
Introduction to Computer Science
Introduction to Computer Science
Just Basic Lessons 9 Mr. Kalmes.
By Himanshi dixit 11th ’B’
String Class.
More Basics of Python Common types of data we will work with
CMPT 120 Lecture 10 – Unit 2 – Cryptography and Encryption –
Primitive Data Types and Operators
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Strings

KAHOOT

String Data Type A string is a sequence of characters A string literal uses quotes ‘Hello’ or “Hello” For strings, + means “concatenate” When a string contains numbers, it is still a string We can convert numbers in a string into a number using int()

Strings Have Length b a n a n a 1 2 3 4 5 There is a built-in function len that gives us the length of a string b a n a n a 1 2 3 4 5 >>> fruit = 'banana'>>> print len(fruit)6

Len Function len() function >>> fruit = 'banana'>>> x = len(fruit) >>> print x6 A function is some stored code that we use. A function takes some input and produces an output. len() function 'banana' (a string) 6 (a number) Guido wrote this code

Slicing Strings M o n t y P y t h o n 1 2 3 4 5 6 7 8 9 10 11 1 2 3 4 5 6 7 8 9 10 11 s = 'Monty Python‘ print s[0:4] Mont print s[6:7] P print s[6:20] Python

Slicing Strings s = 'Monty Python‘ print s[:2]Mo print s[8:]thon 1 2 3 4 5 6 7 8 9 10 11 If we leave off the first number or the last number of the slice, it is assumed to be the beginning or end of the string respectively s = 'Monty Python‘ print s[:2]Mo print s[8:]thon print s[:]Monty Python

String Concatenation a = 'Hello‘ b = a + 'There‘ print (b) HelloThere c = a + ' ' + 'There‘ print (c) Hello There

Using in as an Operator fruit = 'banana‘ 'n' in fruit True 'm' in fruit False 'nan' in fruit if 'a' in fruit : print ('Found it!‘) Found it! The in keyword can also be used to check to see if one string is "in" another string The in expression is a logical expression and returns True or False and can be used in an if statement

String Library str.capitalize() str.center(width[, fillchar]) str.endswith(suffix[, start[, end]]) str.find(sub[, start[, end]]) str.lstrip([chars]) str.replace(old, new[, count]) str.lower() str.rstrip([chars]) str.strip([chars]) str.upper() http://docs.python.org/lib/string-methods.html

KAHOOT