- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
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.
- Related Articles
- 10 Interesting Python Cool Tricks
- What are Some Cool Java Debugging Tips?
- What makes blockchain secure?
- What makes Telnet vulnerable?
- What makes things visible?
- What are some cool websites to pass time?
- What makes a mind creative?
- What makes the rayon rough?
- What makes elections in India democratic?
- What makes something to go viral?
- What makes sprouted grains more nutritious?
- What makes the blood look red?
- What makes a YouTube Video Trending?
- What makes John Donne a unique poet?
- What makes children get attracted towards particular colors?