Python Devlopment






Built-in Operators



Following are the built-in operators in lists.

1. Concatenation

The concatenation operator works in list in the same way it does in a string. This operator concatenates two strings. This is done by + operator in Python.

a=[10,20,30]
b=[40,50,60]

c=a+b
print(c)

#Output
[10, 20, 30, 40, 50, 60]

 

2. Repetition

The repetition operator works as suggested by its name; it repeats the list for given number of times. Repetition is performed by the * operator

a=[10,20,30]

c=a*3
print(c)

#Output
[10, 20, 30, 10, 20, 30, 10, 20, 30]

In the given example, the list [10,20,30] was repeated 3 times.

 

3. in Operator

The in operator tells the user whether the given string exists in the list or not. It gives a boolean output, i.e. True or False. If the given input exists in the string, its gives True as a output otherwise, False

>>>list=['Hello','Python','Program']
>>>'Hello' in list
True       #Output

>>>'World' in list
False      #Output

>>>a=[10,20,30,40]
>>>10 in a
True       #Output
>>>50 in a
False      #Output