String Handling in Python

String Handling in Python, What is a String?, declaration of strings in Python, concatenating strings, and string comparison in Python.

Python Strings

What is String?

The string is a sequence of characters written in single quotes or in double quotes or in three double quotes.

Examples:
string1= ‘This is single quoted string’;
string2= “This is double quoted string”;
string3= “””This is triple quoted string”””;
print (string1);
print (string2);
print (string3);
————————–
String may have Alphabets, Numbers, and Special Characters

Examples:
a=”India”;
b= “100”;
c =”India123″;
d =”*&%$”;
e = “123*&%$”;
f =”India123*&%$”;
g=”Selenium With Java”

print (a);
print (b);
print (c);
print (d);
print (e);
print (f);
print (g);
————————–
How to use quotation marks in Strings?

Examples:
string1 =’Hello Python Don’t’;
string2 =”Python” Strings”;
print (string1);
print (string2);

use Forward Slash (/) to avoid Syntax errors…

string1 =’Hello Python Don\’t’;
string2 =”Python\” Strings”;
print (string1);
print (string2);

Important Operations on Strings…

1. Finding String length

string1 =”Hello Python”;
print (len(string1));

2. Concatenating Strings

string1 =”Hello “;
string2=”Python”;
print (string1 + string2);
————————–
string1 =”Hello “;
num=100;
print (string1 + str(num));

3. Print a String multiple times

string1 =”Hello “;
print (string1 *10);

4. Check whether the String having all numeric characters?

string1 =”Hello”;
print (string1.isnumeric()); # False

string2 =”Hello123″;
print (string2.isnumeric()); # False

string3 =”12345″;
print (string3.isnumeric()); # True

5. Check whether the String having all alphabetic characters?

string1 =”Hello”;
print (string1.isalpha()); # True

string2 =”Hello123″;
print (string2.isalpha()); # False

string3 =”12345″;
print (string3.isalpha()); # False


Python Latest Tutorials

Python Tutorial

1. Introduction to Python Programming Language

2. Download and Install Python

3. Python Language Syntax

4. Python Keywords and Identifiers

5. Python Variables

6. Python Data Types

7. Python Operators

8. Python Conditional Statements

9. Python Loop Statements

10. String Handling in Python

11. Python Lists

12. Python Tuples

13. Dictionaries in Python

14. Python Modules

15. File Handling in Python

Follow me on social media:

1 thought on “String Handling in Python”

Leave a Comment