- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
String Special Operators in Python
Assume string variable a holds 'Hello' and variable b holds 'Python', then −
Sr.No | Operator & Description | Example |
---|---|---|
1 | + Concatenation - Adds values on either side of the operator | a + b will give HelloPython |
2 | * Repetition - Creates new strings, concatenating multiple copies of the same string | a*2 will give-HelloHello |
3 | [] Slice - Gives the character from the given index | a[1] will give e |
4 | [ : ] Range Slice - Gives the characters from the given range | a[1:4] will give ell |
5 | in Membership - Returns true if a character exists in the given string | H in a will give 1 |
6 | not in Membership - Returns true if a character does not exist in the given string | M not in a will give 1 |
7 | r/R Raw String - Suppresses actual meaning of Escape characters. The syntax for raw strings is exactly the same as for normal strings with the exception of the raw string operator, the letter "r," which precedes the quotation marks. The "r" can be lowercase (r) or uppercase (R) and must be placed immediately preceding the first quote mark. | print r'\n' prints \n and print R'\n'prints \ n |
8 | % Format - Performs String formatting | See at next section |
- Related Articles
- Special Operators in SQL
- Logical Operators on String in Python?
- Special Binary String in C++
- C# String Operators
- PHP String Operators
- Program to check if a string contains any special character in Python
- Logical Operators on String in C#
- Logical Operators on String in Java
- Check if a string can be rearranged to form special palindrome in Python
- Count special palindromes in a String in C++
- Division Operators in Python?
- Basic Operators in Python
- Overloading Operators in Python
- How to remove all special characters, punctuation and spaces from a string in Python?
- What is special about string class in Java?

Advertisements