6 Magical Python Tips For Developer

 
6 magical Python Tips And Tricks For Programmers
Python is one of the most preferred languages out there. Its brevity and high readability makes it so popular among all programmers.So here are few of the tips and tricks you can use to bring up your P…


This content originally appeared on DEV Community and was authored by codeifys

 

6 magical Python Tips And Tricks For Programmers

Python is one of the most preferred languages out there. Its brevity and high readability makes it so popular among all programmers.
So here are few of the tips and tricks you can use to bring up your Python programming game.

1. In-Place Swapping Of Two Numbers.




x, y = 10, 20



print(x, y)



x, y = y, x



print(x, y)

Output:
10 20

20 10

2. Reversing a string in Python




a = "codelivly"



print("Reverse is", a[::-1])

Output:
 Reverse is ylviledoc

3. Create a single string from all the elements in list




a = ["Coding", "is", "life"]



print(" ".join(a))

Output:
Coding is life

4. Chaining Of Comparison Operators.




n = 10



result = 1 < n < 20



print(result)



result = 1 > n <= 9



print(result)

Output:
True

False

4. Print The File Path Of Imported Modules.




import os



import socket



  

print(os)



print(socket)

Output:
<module 'os' from '/usr/lib/python3.5/os.py'>

<module 'socket' from '/usr/lib/python3.5/socket.py'>

5. Use Of Enums In Python.




class MyName:



    Coding, is, life = range(3)



  

print(MyName.Coding)



print(MyName.is)



print(MyName.life)

Output:
2

1

2

6. Return Multiple Values From Functions.




def x():



    return 1, 2, 3, 4



a, b, c, d = x()



  

print(a, b, c, d)

Output:
1 2 3 4

Article Was Originally Published to : 
10 Magical Python Tips For Every Developer




This content originally appeared on DEV Community and was authored by codeifys


Print Share Comment Cite Upload Translate Updates
APA

codeifys | Sciencx (2021-08-10T09:29:25+00:00) 6 Magical Python Tips For Developer. Retrieved from https://www.scien.cx/2021/08/10/6-magical-python-tips-for-developer/

MLA
" » 6 Magical Python Tips For Developer." codeifys | Sciencx - Tuesday August 10, 2021, https://www.scien.cx/2021/08/10/6-magical-python-tips-for-developer/
HARVARD
codeifys | Sciencx Tuesday August 10, 2021 » 6 Magical Python Tips For Developer., viewed ,<https://www.scien.cx/2021/08/10/6-magical-python-tips-for-developer/>
VANCOUVER
codeifys | Sciencx - » 6 Magical Python Tips For Developer. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/10/6-magical-python-tips-for-developer/
CHICAGO
" » 6 Magical Python Tips For Developer." codeifys | Sciencx - Accessed . https://www.scien.cx/2021/08/10/6-magical-python-tips-for-developer/
IEEE
" » 6 Magical Python Tips For Developer." codeifys | Sciencx [Online]. Available: https://www.scien.cx/2021/08/10/6-magical-python-tips-for-developer/. [Accessed: ]
rf:citation
» 6 Magical Python Tips For Developer | codeifys | Sciencx | https://www.scien.cx/2021/08/10/6-magical-python-tips-for-developer/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.