0% found this document useful (0 votes)
6 views1 page

Python String Operators Explained

The document explains the usage of the * operator for string types, which requires one argument to be an integer and the other a string, while highlighting that using a float or another string will result in a TypeError. It also discusses relational operators applicable to both integers and strings, providing examples of their usage and outcomes. Additionally, it notes that division and modulus by zero will always raise a ZeroDivisionError.

Uploaded by

vishnu200121
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Python String Operators Explained

The document explains the usage of the * operator for string types, which requires one argument to be an integer and the other a string, while highlighting that using a float or another string will result in a TypeError. It also discusses relational operators applicable to both integers and strings, providing examples of their usage and outcomes. Additionally, it notes that division and modulus by zero will always raise a ZeroDivisionError.

Uploaded by

vishnu200121
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

If we use * operator for str type then compulsory one argument should be int and other

argument should be str type.

2*"durga"
"durga"*2
2.5*"durga" ==>TypeError: can't multiply sequence by non-int of type 'float'
"durga"*"durga"==>TypeError: can't multiply sequence by non-int of type 'str'

+====>String concatenation operator


* ===>String multiplication operator

Note: For any number x,

x/0 and x%0 always raises "ZeroDivisionError"

10/0
10.0/0
.....

Relational Operators:
>,>=,<,<=

Eg 1:

1) a=10
2) b=20
3) print("a > b is ",a>b)
4) print("a >= b is ",a>=b)
5) print("a < b is ",a<b)
6) print("a <= b is ",a<=b)
7)
8) a > b is False
9) a >= b is False
10) a < b is True
11) a <= b is True

We can apply relational operators for str types also

Eg 2:

1) a="durga"
2) b="durga"
3) print("a > b is ",a>b)
4) print("a >= b is ",a>=b)
5) print("a < b is ",a<b)

nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
3  040 – 64 51 27 86, 80 96 96 96 96, 92 46 21 21 43 | [Link]

You might also like