Python Random Tips #6

This is not a Python Starter Tutorial but advanced Python Tips in a Random Order.

This is some interesting Python tips for your review:

#1 Easy way to reverse using slice.

The above result gives the reverse order of the input number using -1 in the slice step.

#2 How to get the last element from the list?

#3 What is the difference between remove and del?

The index 4 from the list mumber2 (5th element ie., value 6) is deleted.

But if we want the actual ‘value’ to be removed, then we can use remove.

In the above example, the number 4 is removed from ‘number2’. Please note that this is NOT the index 4 but the actual value 4.

#4 Do you know?

Size of empty string in Python?

Size of empty list or tuple?

Here is the Python code to find the size of these inputs:

That’s all for now. Enjoy and happy learning.

Leave a comment

Design a site like this with WordPress.com
Get started