Some interesting and fact information about Python
As like other program there no braces to delimit the code. Indentation is mandatory in python to specifies, the block of code is execute when particular condition is meet or for number of times iteration to exicute.
l=[1,2,3,4]
for i in l:
if i in l:
print(i) // out put = [1,2,3,4]
- _ underscore operator use to get the value of the last expression.
Many of them used IDLEas a calculator, so for get the result of the last expression use an underscore.
>>> 2*3
6
>>>2*_
12
- For loop and while loop can have else statements.
- else statement is not only limited to if and try, in here we can use it to looping statement also.
- else block is executed only when the loop get terminated normally. If loop raise any error or break statement, then the code under the else is not get executed.
for i in range(3): \\ out out: in range
print(“in range”) in range
else: in range
print (”out range”) out range
- we can form chain comparison
conditions may contain more than one comparison at once.
>>>1<2>3<4
False
- Python supports negative index.
With help of negative index we can easily reversed the list.
>>> num=[1,2,3,4]
>>>num[::-1]
[4,3,2,1]
- Python supports multiple assignment in one statement.
- We can assign same value to multiple variable and we can assign different values to different variable in single statement.
- In python swapping is done in quicker and in only 1 line of code.
>>> a,b=10,20
>>> print(a,b)
(10, 20)
>>> a,b=b,a
>>> print(a,b)
(20, 10)
- In python we can return multiple values from a function.
Yes function can return more then one value as a tuple
def fun():
return 1, 24.5, "biya"
reg_no,marks,name=fun()
print(reg_no,name,marks) // out put = (1, 'biya', 24.5)
Tim Peters, a major contributor to the Python community, wrote this poem to highlight the philosophies of Python. If you type in “import this” in your Python IDLE, you’ll find that poem.
- String literals concatenate together.
If you type in string literals separated by a space, Python concatenates them together. So, ‘Hello’ ‘World’ becomes ‘HelloWorld’.
>>> 'sookshmas,' ' Beyond' 'knowing' ' game'
'sookshmas, Beyondknowing game'