Top 10 Useful Python Tricks For Writing Better Code
-These tricks will save time and increase your efficiency
The following is a list of really useful python tricks. It is in no particular order.
- Underscore place holders
- Used when working with large numbers. It helps you to keep track of how many digits there are in a number which would be hard by just looking at them. It is the substitute of commas in paperwork as separators.
2. Ternary Conditions
- Saves you from writing unnecessary code when evaluating something based on a condition being true or false.
3. In place swapping of two numbers.
- Case 1: Using only a certain number of values and ignoring others.
- Case 2: Telling python to set the remaining values to the last variable
5. Reversing a string
6.Use of Enumerate
- Used when you want a counter while looping over a list
- Allows you to loop over 2 lists at once.
8.Create a string from all elements in a list
- This function opens the documentation of a module
- It is a module used for inputting sensitive information e.g passwords since users don’t want their passwords displayed on the screen.
- Morris Bundi
- Mar, 31 2022