Important Notice:

Other String Operations

Other String Operations

3 views 2 min read

Other String Operations :-  Repetition Operator (*) :-

Repetition Operator (*) का उपयोग किसी String को एक निश्चित संख्या (Number of Times) तक दोहराने (Repeat) के लिए किया जाता है।

The Repetition Operator (*) is used to repeat a string a specified number of times.

Syntax-

string * number

Example 1 -

text = "Hi "

print(text * 3)
 
Output -
Hi Hi Hi

Membership Operators (in, not in) in Python :-

Membership Operators का उपयोग यह जाँचने के लिए किया जाता है कि कोई Value (मान) किसी Sequence (क्रम) या Collection (संग्रह) जैसे String, List, Tuple, Set या Dictionary में मौजूद है या नहीं।

Membership Operators are used to check whether a value exists in a sequence or collection such as a String, List, Tuple, Set, or Dictionary.

Python has two Membership Operators:

Python में दो Membership Operators होते हैं:/ Python has two Membership Operators:

  1. in
  2. not in

1. in Operator :-

in Operator यह जाँचता है कि कोई Value किसी Collection में मौजूद है या नहीं।

यदि Value मिल जाती है, तो परिणाम True होता है, अन्यथा False।

English:

The in operator checks whether a value exists in a collection.

If the value is found, it returns True; otherwise, it returns False.

Example :-

text = "Python"

print("Py" in text)
print("th" in text)
print("Java" in text)
 
Output-
True
True
False
 
2. Operator: not in :-

यदि Character या Substring मौजूद नहीं है, तो True लौटाता है।

Example -
text = "Python"

print("Java" not in text)
print("Py" not in text)
 
Output-
True
False
 
3. Comparison Operators (==, !=, <, >, <=, >=) :-

Comparison Operators दो Strings की तुलना (Compare) करते हैं। Python तुलना Unicode (Lexicographical Order) के आधार पर करता है।

English

Comparison operators compare two strings. Python compares strings based on their Unicode (Lexicographical Order) values.

Example -
a = "Apple"
b = "Banana"

print(a == b)
print(a != b)
print(a < b)
print(a > b)
print(a <= b)
print(a >= b)
Output-
False
True
True
False
True
False

 

4. Length Function (len())

len() Function String में मौजूद कुल Characters की संख्या लौटाता है।

English

The len() function returns the total number of characters in a string.

Syntax -

len(string)

Example:-

text = "Python"

print(len(text))
 
Output-
6
 
 

Related Notes