STRING MANUPILATION STRING OPERATORS TYPES OF STRING OPERATORS

  • Slides: 8
Download presentation
STRING MANUPILATION

STRING MANUPILATION

 STRING OPERATORS TYPES OF STRING OPERATORS: - BASIC OPERATORS MEMBERSHIP OPERATORS COMPARISON OPERATORS

STRING OPERATORS TYPES OF STRING OPERATORS: - BASIC OPERATORS MEMBERSHIP OPERATORS COMPARISON OPERATORS

1. BASIC OPERATORS THE TWO BASIC OPERATORS OF STRING ARE: - + AND *.

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: - str 1 = 'Hello' str 2 ='World!' print('str 1 + str 2 = ', str 1 + str 2) REPLICATION: - str 1 = 'Hello' str 2 ='World!' print('str 1 * 3 =', str 1 * 3)

2. MEMBERSHIP OPERATORS THERE ARE TWO MEMBERSHIP OPERATORS FOR STRING. THESE ARE IN AND

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

3. COMPARISION OPERATORS Python string comparison is performed using the characters in both strings.

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(fruit 1 == 'Apple') # TRUE print(fruit 1 != 'Apple') # FALSE print(fruit 1 < 'Apple') # FALSE print(fruit 1 > 'Apple') # FALSE print(fruit 1 <= 'Apple') # TRUE print(fruit 1 >= 'Apple') # TRUE

STRING FUNCTIONS Python String Functions capitalize() - Returns the string with first letter capitalized

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.

Python String Functions format() - Format the given string. format_map() - Format the given

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 Value. Error 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.

THE END MADE BY: - CHETANYA SHARMA

THE END MADE BY: - CHETANYA SHARMA