Python tips

wapping of two variable numbers

We can also do in-place swapping of two variables numbers so we can use their swapped values in the program. Example: Look at the following Python program: Output:

Printing given string number of times

We can print a given string 'n' number of times in the output simply by using 'String Name * n' syntax into the print statement. It will print the given string n number of times in continuation in output. Example: Output:

Printing the most occurred element of a list

We have given a list with a number of elements in it, and there are many elements in it that are repeated more than one time. Now, if we want to print the number of elements that are occurred most in the list and it is the same as finding mode in statistics from the given data of numbers. We use max() and count function to get the result of the most occurred element. Example: Output: