Out of the following operators, which ones can be used with strings?
= , - , * , / , // , % , > , < > , in, not in, <=
Answers
Answer:
=, *, >, in, not in, <=
Explanation:
These operators can be used with strings.
=, *, >, in, not in, <=
Operators in python :
Python has different types of operators like
1. Arithmetic operators
- Addition " + " used as x + y
- Subtraction " - " used as x - y
- Multiplication " * " used as x * y
- Division " / " used as x / y
- Modulus " % " used as x % y
- Exponentiation " ** " used as x ** y
- Floor division " // " used as x // y
2. Assignment operators
- = as x = 5
- += as x = x + 3
- -= as x = x - 3
- *= as x = x * 3
- /= as x = x / 3
- %= as x = x % 3
- //= as x = x // 3
- **= as x = x ** 3
- &= as x = x & 3
- |= as x = x | 3
- ^= as x = x ^ 3
- >>= as x = x >> 3
- <<= as x = x << 3
3. Comparison operators
- == as Equal
- != as Not equal
- > as Greater than
- < as Less than
- >= as Greater than or equal to
- <= as Less than or equal to
4. Logical operators
- and - returns if both statements are true.
- or - returns true if one statement is true.
- not - returns reverse result.
5. Identity operators
- is - returns true it both the variables are same objects.
- is not - returns true it both the variables are not the same objects.
6. Bitwise operators
- & - AND
- | - OR
- ^ - XOR
- ~ - NOT
- << - Zero fill left shift
- >> - Signed right shift
#SPJ2
Answer:
The following operators can be used with strings:
=, *, in, not in
Explanation:
String Operators
Strings are the collection of characters that are immutable in nature. Once a string is created it cannot be later modified. There are many operators that could be used on the strings.
- Assignment Operator(=): It is used to assign the value to the string type variable.
For example:
name = "Vishaka"
print(name) #OUTPUT: Vishaka
- Multiply Operator(*): It is used to repeat or multiply the characters of the string.
For example:
example = "ABC"
print(example*2) #OUTPUT ABCABC
- in operator: This operator is used to check whether a character is present in a string or not.
For example:
print('A' in 'ABC') #OUTPUT: True
- not in operator: This operator is just the opposite of 'in' operator. It works as an invertor in strings.
For example:
print('S' not in 'ABC') #OUTPUT: True
#SPJ2