By Himanshi dixit 11th ’B’

Slides:



Advertisements
Similar presentations
Intro to Scala Lists. Scala Lists are always immutable. This means that a list in Scala, once created, will remain the same.
Advertisements

Python Mini-Course University of Oklahoma Department of Psychology Day 4 – Lesson 15 Tuples 5/02/09 Python Mini-Course: Day 4 – Lesson 15 1.
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.
0 PROGRAMMING IN HASKELL Chapter 5 - List Comprehensions.
Week 10 Recap CSE 115 Spring For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each.
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.
Guide to Programming with Python
October 4, 2005ICP: Chapter 4: For Loops, Strings, and Tuples 1 Introduction to Computer Programming Chapter 4: For Loops, Strings, and Tuples Michael.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 More About Strings.
2440: 211 Interactive Web Programming Expressions & Operators.
Strings The Basics. Strings can refer to a string variable as one variable or as many different components (characters) string values are delimited by.
Strings CS303E: Elements of Computers and Programming.
Built-in Data Structures in Python An Introduction.
10. Python - Lists The list is a most versatile datatype available in Python, which can be written as a list of comma-separated values (items) between.
Lecture 19 - More on Lists, Slicing Lists, List Functions COMPSCI 101 Principles of Programming.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 8 Lists and Tuples.
6 Strings and Tuples © 2010 David A Watt, University of Glasgow Accelerated Programming 2 Part I: Python Programming 1.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 8: Fun with strings.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
C++ String Class nalhareqi©2012. string u The string is any sequence of characters u To use strings, you need to include the header u The string is one.
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
Mr. Fowler Computer Science 14 Feb 2011 Strings in Python.
Strings The Basics. Strings a collection data type can refer to a string variable as one variable or as many different components (characters) string.
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
3 Basics © 2010 David A Watt, University of Glasgow Accelerated Programming 2 Part I: Python Programming.
Chapter 10 Loops: while and for CSC1310 Fall 2009.
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.
C Language 1 Program Looping. C Language2 Topics Program looping Program looping Relational operators / expressions Relational operators / expressions.
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.
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.
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.
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.
Computer Science 18 Feb 2011 Strings in Python. Introduction Prior experience  Defining string variables  Getting user input  Printing strings Lesson.
Guide to Programming with Python Chapter Four Strings, and Tuples; for Loops: The Word Jumble Game.
String and Lists Dr. José M. Reyes Álamo.
Set Comprehensions In mathematics, the comprehension notation can be used to construct new sets from old sets. {x2 | x  {1...5}} The set {1,4,9,16,25}
Set Comprehensions In mathematics, the comprehension notation can be used to construct new sets from old sets. {x2 | x  {1...5}} The set {1,4,9,16,25}
Using Molecular Biology to Teach Computer Science
CSc 120 Introduction to Computer Programing II Adapted from slides by
CMSC201 Computer Science I for Majors Lecture 14 – Tuples
Tuples and Lists.
CISC101 Reminders Quiz 2 this week.
Arithmetic operations, decisions and looping
8 – Lists and tuples John R. Woodward.
Chapter 8 More on Strings and Special Methods
CEV208 Computer Programming
String and Lists Dr. José M. Reyes Álamo.
Lists in Python Outputting lists.
Topics Sequences Introduction to Lists List Slicing
Python Primer 1: Types and Operators
Basic String Operations
PROGRAMMING IN HASKELL
15-110: Principles of Computing
15-110: Principles of Computing
Topics Sequences Lists Copying Lists Processing Lists
The Data Element.
By- Anshul Kumar Class: XI “B”
CISC101 Reminders Assignment 2 due today.
Topics Basic String Operations String Slicing
Introduction to Computer Science
Topics Sequences Introduction to Lists List Slicing
CMSC201 Computer Science I for Majors Lecture 16 – Tuples
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
The Data Element.
Topics Basic String Operations String Slicing
COMPUTING.
Presentation transcript:

By Himanshi dixit 11th ’B’ STRING MANIPULATION By Himanshi dixit 11th ’B’

INTRODUCTION Strings are sequence of characters. Strings are enclosed in quotes of any type. Ex:- ‘string’, “string” and ‘‘‘string’’’ Strings are immutable. An empty string is a string that has 0 characters. Ex:- “” Each character of string has a unique position-id /index. -6 -5 -4 -3 -2 -1 P T H O

INDEX The indexes of a string begin from 0 to (length-1) in forward direction and -length in backward direction -6 -5 -4 -3 -2 -1 P Y T H O N 0 1 2 3 4 5

TRAVERSING A STRING Traversing refers to iterating through the elements of a string one character at a time. Individual characters of a string are accessible through the unique index of each character. Example:- name=‘superb’ for i in name : print (i, ‘-’, end=“ “) -This loop will traverse through string name character by character. The code will print: s-u-p-e-r-b-

String operators Basic operators Examples Basic operators The two basic operators of strings are : + and *. String concatenation operator + The + operator creates a new string by joining the two operand strings, e.g., “tea”+ “pot “ Will result into- “teapot” Expressions Will result into ‘1’+’1’ ‘11’ “a”+”0” “a0” ‘123’+’abc’ ‘123abc’ NOTE : The + oprator has to have both operands of the same type either of number types or of string types.

* Operator performs replication rather than multiplication in strings. STRING REPLICATION OPERATOR * * Operator performs replication rather than multiplication in strings. For replication operator ,python creates a new string that is a number of repetitions of the input string. Eg :- 3* “go! ” will return “go!go!go! ” The * operator has to either have both operands of the number types (for multiplication)or one string type and one number type (for replication). It cannot work with both operands of string types.

Working of python * operator Operands data type Operation performed by * Example Numbers Multiplication 9 * 9=18 String , Number Replication ‘#’ * 3= ‘###’ Number , String 3 * ’#’=‘###’

MEMBERSHIP OPERATORS There are two membership operators for strings i.e. in and not in. Membership operators (when used with strings) , require both operands used with them are of string type, i.e. <string> in <string> <string> not in <string> Eg: “12” in “xyz” “12” not in “xyz”

COMPARISON OPERATORS Python standard comparison operators i.e., all relational operators (<,<=,>,>=,==,!=) apply to strings also. Eg: “a” == “a” will give true “A” != “a” will give true “ABC” == “abc” will give false For comparisons like less than (<) or greater than (>) , common characters and their ordinal values should be known.

Common characters and their ordinal values ‘0’ to ‘9’ 48 to 57 ‘A’ to ‘Z’ 65 to 90 ‘a’ to ‘z’ 97 to 122 ‘a’ < ‘A’ will give false ‘abc’ <= ‘ABCD’ will give false

Determining ordinal value of single character Built -in function ord() that takes a single character and returns the corresponding ordinal Unicode value. ord ( <single -character>) Eg: ord ( “A”) 65 The opposite of ord() function is chr() The chr() takes the ordinal value in integer form and returns the character corresponding to that ordinal value. chr(<int>)

Thank You