Commit 81af9a1f by Blaise Li

### Hide Python 2 comment.

parent 4d17374f
Pipeline #58080 passed with stages
in 12 seconds
 ... @@ -100,25 +100,35 @@ If we modify the state of the list itself, but not the references to this object ... @@ -100,25 +100,35 @@ If we modify the state of the list itself, but not the references to this object Exercise Exercise -------- -------- wihout using python shell, what is the results of the following statements: .. note:: .. note:: sum is a function which return the sum of each elements of a list. ``sum`` is a function which return the sum of all the elements of a list. Wihout using the Python shell, tell what are the effects of the following statements:: :: x = [1, 2, 3, 4] x = [1, 2, 3, 4] x[3] = -4 # what is the value of x now ? x[3] = -4 # What is the value of x now? y = sum(x)/len(x) #what is the value of y ? why ? y = sum(x) / len(x) # What is the value of y? Why? Solution (using the Python shell ;) ):: >>> x = [1, 2, 3, 4] >>> x[3] = -4 >>> x [1, 2, 3, -4] >>> y = sum(x) / len(x) >>> y 0.5 Here, we compute the mean of the values contained in the list ``x``, after having changed its last element to -4. y = 0.5 .. .. warning:: .. warning:: In python2 the result is :: .. In python2 the result is :: y = 0 .. y = 0 because sum(x) is an integer, len(x) is also an integer so in python2.x the result is an integer, .. because sum(x) is an integer, len(x) is also an integer so in python2.x the result is an integer, all the digits after the periods are discarded. all the digits after the periods are discarded. ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}