- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What makes Python Cool?
In this article, we will learn about what all features makes python cool and different from other languages.
The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. The flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!
Swapping of two variables in one line
We can assign values to multiple variables at the same time in the form of single statement as shown below
a = 201 b = 786 print("Before swapping value of a ="+str(a)+" and b = "+str(b)) #Before swapping value a, b = b, a print("After swapping value of a ="+str(a)+" and b = "+str(b)) #After swapping value
Before swapping value of a =201 and b = 786 After swapping value of a =786 and b = 201
The enumerated type is used to traverse the list and similar types without actually knowing their lengths.
mylist = ['t','u','t','o','r','i','a','l'] for i, value in enumerate(mylist): print( i, ': ', value)
0 : t 1 : u 2 : t 3 : o 4 : r 5 : i 6 : a 7 : l
By using zip method we can traverse over multiple lists at the same time as shown in the code below.
mylist1 = ['t','u','t','o','r','i','a','l'] mylist2 = ['p','o','i','n','t'] for i,j in zip(mylist1,mylist2): print( i, ':', j)
t : p u : o t : i o : n r : t
Reversing the list
By using built-in reversed method() we can directly obtain the reversed list without any looping construct
list_inp = ['t','u','t','o','r','i','a','l'] print(list(reversed(list_inp)))
['l', 'a', 'i', 'r', 'o', 't', 'u', 't']
Use Interactive "_" Operator.
This operator is used on the command line to print or display the output of the previous operation performed.
>>> 12 + 12 24 >>> _ 24 >>> print(_) 24
As we all are aware that there is no need for data type declaration in Python and we can change the data type of variables multiple times in a program.
In this article, we learnt about what all features are present in Python which makes it cool and more attractive to programmers.
- 10 Interesting Python Cool Tricks
- What makes blockchain secure?
- What makes Telnet vulnerable?
- What makes a mind creative?
- What makes elections in India democratic?
- What makes something to go viral?
- What are some cool websites to pass time?
- What makes John Donne a unique poet?
- What makes children get attracted towards particular colors?
- What makes a person a champion at anything?
- What Makes Performance Management Systems Ineffective and Uninspiring?
- What makes Baahubali 2 such a great cinematic experience?
- How does a refrigerator keep the temperature cool inside it?
- Many of my friends find girls who smoke cool, why?
- Will Ram Gopal Varma makes movie on himself?