0% found this document useful (0 votes)
11 views

Pyth Scribd

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Pyth Scribd

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Get Unique Items in an array

a = [1, 2, 2, 3] set(a) {1, 2, 3}


list(set(a))
[1, 2, 3] sorted(set(langs)):
multiline comments use “””
>>> def func_test():
"""test commentr 1
testcomment 2
test comment3"""
>>> func_test.__doc__

'test commentr 1\n\n testcomment 2\ntest comment3


A=[]
For x in range(10):
a.append(x*2)
a=[0,2,4,6,8,10,…]
pep8:coding conventions for python
what is virtual environment in python
from operator import mul
>>> c=reduce(mul,range(1,10)) As far as I understand, the reduce function
takes a list l and a function f. Then, it calls the function f on first two elements of
the list and then repeatedly calls the function f with the next list element and the
previous result.
Difference between range and xrange
In Python 2.x, range() generates a list, possibly a very large one.
Sometimes that's exactly what you need. But other times, you're just
using the list as an iterable, perhaps as a counter, or simply as a way to make a
loop go a fixed number of times now we use xrange()

division of an integer by another integer yelds an integer in version 2.x of python


in py 3.x it is float and print statement also varies

c=1/2 print c:0 c=1/2.2 print c:0.45


type(c) 0.45
int float

type(fun()) gives return value type of function


a=1+1j or a=complex(1,1)
a.real =real value x.conjugate() x.imag abs(3 + 4j)=5.0
pritn a>x gives error
print a>b

Traceback (most recent call last):


File "<pyshell#57>", line 1, in <module>
print a>b
TypeError: no ordering relation is defined for complex numbers
>>> print a=b
SyntaxError: invalid syntax
>>> print a==b
False
>>> print abs(a)>abs(b)
False
>>> print abs(a)<abs(b)
True
A=4
A**2=4^2 s='hi how are you'
>>> a=s.split();print a
['hi', 'how', 'are', 'you']
print " ".join(s.split())
hi how are you
Following is the syntax for split() method:
str.split(str="", num=string.count(str)).
Parameters
● str -- This is any delimeter, by default it is space.

You might also like