Python lists concatenation

We can simply use '+' operator on two lists to join them. For example, 'x' and 'y' are two lists. If we write x+y, the list 'y' is joined at the end of the list 'x'.

lists concatenation

CopiedCopy Code

x = [10, 20, 30, 40, 50] 
y = [100, 110, 120] 
print(x+y)

Repetition of Lists:

We can repeat the elements of a list 'n' number of times using '*' operator. For example, if we write x*n, the list 'x' will be repeated for n times as:

CopiedCopy Code

print(x*2) # repeat the list x for 2 times

Membership in Lists

We can check if an element is a member of a list or not by using 'in' and 'not in' operator. If the element is a member of the list, then 'in' operator returns True else False. If the element is not in the list, then 'not in' operator returns True else False. See the examples below:

CopiedCopy Code

x = [10, 20, 30, 40, 50] 
a = 20 
print(a in x)

The preceding statements will give: True

If you write,

CopiedCopy Code

print(a not in x) #check if a is not a member of x

Then, it will give False