Dear Readers,
Here I would like to Share 5 amazing or unbelievable facts about python programming language which you might haven't noticed yet!!
So without Wasting your time lets just jump to the facts:
1. What if I said you to compare your name with your best friends name ,sounds illogical right?:
---> Well in python you can actually compare strings based on lexicographic values(comparing dictionary order wise)
True (since d comes after b if seen alphabetically)
2. Do you really want to know BTS(behind the scenes ) in python programming?:
--->Well dis module is there for your aide (it means disassemble ) so it disassembles your code into human readable format and lets you know what your interpreter is doing
1
2
3
4
5
6
7
8
9
10
11
12
13
14 | import dis
def hello():
print('Hello')
print(dis.dis(hello))
#Output:
3 0 LOAD_GLOBAL 0 (print)
2 LOAD_CONST 1 ('Hello')
4 CALL_FUNCTION 1
6 POP_TOP
8 LOAD_CONST 0 (None)
10 RETURN_VALUE
None
|
For more info click me!
3. We can compare tuples and lists also in python(for coders):
--->
1
2
3
4
5
6
7
8
9
10
11
12 | 3,4,5 < 6,7,8
(3, 4, True, 7, 8)
# here our interpreter takes it as 3,4,(5<6),7,8
# hence we use
>>> (3,4,5)<(5,3,7)
True
>>> (3,4,5)<(2,1,9)
False
# so majority wins more i.e more trues make # output true
# similarly you can use lists
>>>[1,2,3]<[2,3,4]
True
|
4. How would you take logical interpretation for True or False statements?,
--->Well our Python has something for us in that case
In python any value not equal to zero(in number terms) is true and you can use True in place of 1 as well and None,0,'',[],{},(),etc depict False
1
2
3
4
5 | >>> True == 1
True
>>> True is 1
False
# they share equal values but they are not same
|
5.How should you code, or what should be the format?
---> Well guess what guys python solved this as well with the zen of python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 | >>> import this
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.
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!
|
So guys I hope you enjoyed it reading this blog as much as I enjoyed Writing it please comment and subscribe for more such blogs on regular basis. Also you can check more of my blogs like random module in python, simple calculator