Download presentation
Presentation is loading. Please wait.
1
STRING MANUPILATION
2
STRING OPERATORS TYPES OF STRING OPERATORS:- BASIC OPERATORS
MEMBERSHIP OPERATORS COMPARISON OPERATORS
3
1. BASIC OPERATORS THE TWO BASIC OPERATORS OF STRING ARE:- + AND *. YOU HAVE USED THESE ARITHMETRIC OPERATORS BEFORE FOR ADDITION AND MULTIPLICATION RESPECTIVELY. BUT WHEN USED WITH STRINGS, + OPERATOR PERFORMS CONCATENATION RATHER THAN ADDITION AND * OPERATOR PERFORMS REPLICATION RATHER THAN MULTIPLICATION. EXAMPLES:- CONCATENATION:- str1 = 'Hello' str2 ='World!' print('str1 + str2 = ', str1 + str2) REPLICATION:- print('str1 * 3 =', str1 * 3)
4
2. MEMBERSHIP OPERATORS THERE ARE TWO MEMBERSHIP OPERATORS FOR STRING .THESE ARE IN AND NOT IN. IN:- RETURNS TRUE IF A CHARACTER OR A SUBSTRING EXISTS IN THE GIVEN STRING; FALSE OTHERWISE. EX:- "A" in "HEYA" # RETURN TRUE NOT IN:- RETURNS TRUE IF A CHARACTER OR A SUBSTRING DOES NOT EXIST IN THE GIVEN STRING; FALSE OTHERWISE. EX:- "jap" not in "JAPAN" # RETURN TRUE BECAUSE PYTHON IS CASE- SENSITIVE
5
3. COMPARISION OPERATORS
Python string comparison is performed using the characters in both strings. The characters in both strings are compared one by one. When different characters are found then their Unicode value is compared. The character with lower Unicode value is considered to be smaller. EXAMPLES:- print(fruit1 == 'Apple') # TRUE print(fruit1 != 'Apple') # FALSE print(fruit1 < 'Apple') # FALSE print(fruit1 > 'Apple') # FALSE print(fruit1 <= 'Apple') # TRUE print(fruit1 >= 'Apple') # TRUE
6
STRING FUNCTIONS Python String Functions
capitalize() - Returns the string with first letter capitalized and the rest lowercased. casefold() - Returns a lowercase string, generally used for caseless matching. This is more aggressive than the lower() method. center() - Center the string within the specified width with optional fill character. count() - Count the non-overlapping occurrence of supplied substring in the string. encode() - Return the encoded version of the string as a bytes object. endswith() - Returns ture if the string ends with the supplied substring. expandtabs() - Return a string where all the tab characters are replaced by the supplied number of spaces. find() - Return the index of the first occurrence of supplied substring in the string. Return -1 if not found.
7
Python String Functions
format() - Format the given string. format_map() - Format the given string. index() - Return the index of the first occurrence of supplied substring in the string. Raise ValueError if not found. isalnum() - Return true if the string is non-empty and all characters are alphanumeric. isalpha() - Return true if the string is non-empty and all characters are alphabetic. isdecimal() - Return true if the string is non-empty and all characters are decimal characters. isdigit() - Return true if the string is non-empty and all characters are digits. isidentifier() - Return true if the string is a valid identifier. islower() - Return true if the string has all lowercased characters and at least one is cased character. isnumeric() - Return true if the string is non-empty and all characters are numeric.
8
MADE BY:- CHETANYA SHARMA
THE END MADE BY:- CHETANYA SHARMA
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.