Thursday, August 25, 2022
HomeWordPress DevelopmentIdeas & Methods In Python

Ideas & Methods In Python


On this quick but efficient submit, we’ll focus on a few of the prime suggestions and methods in python that may assist you to write your code quicker 🚀



Reversing a string

s = "This can be a String"
print(s[::-1])
Enter fullscreen mode

Exit fullscreen mode



Eradicating duplicates from an inventory

a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
b = checklist(set(a))
print(b)
Enter fullscreen mode

Exit fullscreen mode



Merging Two or Extra Dictionaries

a = {'a': 1, 'b': 2}
b = {'c': 3, 'd': 4}
c = {**a, **b}
Enter fullscreen mode

Exit fullscreen mode

  • This trick would possibly solely work for Python model >= 3.5



Changing an inventory of strings right into a string

a = ['a', 'b', 'c']
b = ''.be part of(a)
print(b)
Enter fullscreen mode

Exit fullscreen mode



Retrieving the reminiscence dimension

a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print(sys.getsizeof(a), "Bytes")
print(sys.getsizeof(a) / 1024, "Megabytes")
Enter fullscreen mode

Exit fullscreen mode



Formatting Numbers

num1 = 100_000_000_000
num2 = 100_000_000_000
num3 = num1+num2
print(f"{num3:,}")
Enter fullscreen mode

Exit fullscreen mode

  • The output can be 200,000,000,000



Last Ideas

  • This submit might get up to date every so often
  • If you need to say any methods kindly point out them within the remark part under
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments