Posted under » Python updated on 3 Dec 2025
See also List filter, finding and counting duplicates
You can assign a multiline string to a variable by using three quotes
a = """LK Y is a cool dude in Hell.""" b = '''Goh C cant wait to join LK Y.'''
To get the length of a string, use the len() function
a = "Hello World!" print(len(a))
Strings in Python are arrays of bytes representing unicode characters.
a = "Hello World!" print(a[1])
To check if a certain phrase or character is present in a string, we can use the keyword in.
txt = "Hello World"
if "Hell" in txt:
print("Yes, 'Hell' is present.")
The good thing about `in' is that it is not case sensitive. So hello and Hello will be found. Here is an example in list
myls = ['Hello from Anoneh', 'Hello', 'Hello boy!', 'Hi']
for gay in myls:
if "Hell" in gay:
print("Yes, 'Hell' is present.")
else :
print("Not this time")
Check if "cool" is NOT present in the following text:
txt = "Hello World"
if "cool" not in txt:
print("No, 'cool' is NOT present.")
If you want to check the number (count) of `l' in "Hello World",
txt = "Hello World"
counter = txt.count('l')
3
List example
a = [1, 2, 3]
b = 4
if b in a:
print('4 is present!')
else:
print('4 is not present')
You can see that it is exact when integer
For string, you can use the ‘any()’ method. The any() method in Python can be used to check if a certain condition holds for any item in a list. This method returns True if the condition holds for at least one item in the list, and False otherwise.
For example, if you wish to test whether ‘anoneh’ is a part of any of the items of the list, we can do the following:
myls = ['Hello from Anoneh', 'Hello', 'Hello boy!', 'Hi']
if any("Anoneh" in word for word in myls):
print('\'Anoneh\' is there inside the list!')
else:
print('\'Anoneh\' is not there inside the list')
Note that it is case sensitive.
See also Python String into array
It is a bit different from string search in PHP.