Q:

Python:Which way gives better precision

Is there any difference in precision between one time assignment:   
res=n/k

and multiple assignment in for cycle:
for i in range(n):
    res+=1/k

?

A:

Floating-point division a/b is not mathematical division a ÷ b, except in very rare* circumstances.  
Generally, floating point division a/b is a ÷ b + ε.  
This is true for two reasons.

Float numbers (except in rare cases) are an approximation of the decimal number.
a is a + εa.  
b is b + εb.
Float numbers uses a base 2 encoding of the digits to the right of the decimal place.  When you write 3.1, this is expanded to a base-2 approximation that differs from the real value by a small amount.  
Real decimal numbers have the same problem, by the way.  Write down the decimal expansion of 1/3.  Oops.  You have to stop writing decimal places at some point.  Binary floating point numbers have the same problem.
Division has a fixed number of binary places, meaning the answer is truncated.  If there's a repeating binary pattern, it gets chopped.  In rare cases, this doesn't matter.  In general, you've introduced error by doing division.

Therefore, when you do something like repeatedly add 1/k values you're computing
1 ÷ k + ε
And adding those up.  Your result (if you had the right range) would be
n × (1 ÷ k + ε) = n ÷ k + n × ε
You've multiplied the small error, ε, by n.   Making it a big error.  (Except in rare cases.)
This is bad.  Very bad.  All floating point division introduces an error.  Your job as a programmer is to do the algebra to avoid or defer division to prevent this.  Good software design means good algebra to prevent errors being introduced by the division operator.
[* The rare cases. In rare cases, the small error happens to be zero.  The rare cases occur when your floating point values are small whole numbers or fractions that are sums of powers of two 1/2, 1/4, 1/8, etc.  In the rare case that you have a benign number with a benign fractional part, the error will be zero.]  

A:

Sure, they are different, because of how floating point division works.
>>> res = 0
>>> for x in xrange(5000): res += 0.1
... 
>>> res == 5000 * 0.1
False

There's a good explanation in the python official tutorial.

