Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Search results

  1. S

    Python Trying to understand flipping a list

    x = 1 y = 2 x, y, z = x, x, y z, y, z = x, y, z print(x, y, z) The answer here is 1 1 2. My question is how does this process work? I would have thought that the answer would have gone as follows: x = 1, y = 2, z = 1 swap x = 1, x = 2, y = 1 z = 1, y = 1, z = 1 swap x = 1, y = 1, z = 1...
  2. S

    Python Issues with lists in Python

    my_list = [1, 2] for v in range(2): my_list.insert(-1, my_list[v]) print(my_list) The result of this is [1, 1, 1, 2], but I can't honestly comprehend why? Why isn't there a 0 then a 1? why isn't it after the 2 considering it is -1 for the placement in the list? myList = [] for i...
  3. S

    Python Rearranging elements in Python

    I am confused on lines 9-11, how does elem2 change values, surely it would just say as one since it's just swapping values with it's self? It's confusing because in order for this sequence to work it needs to change, I just don't know how it is doing so. def fib(n): if n < 1...
  4. S

    Python insert() function printing the list the opposite way

    myList = [] # creating an empty list for i in range(5): myList.insert(0, i + 1) print(myList) I am new to Python and I am wondering why this outputs the numbers backwards. Surely it starts from 0 and not from the last value?
  5. S

    Python Simple confusion for the del instuction

    hatList = [1, 2, 3, 4, 5] hatList[2] = input(int("Enter an integer number: )") del hatList[4] del hatList[-1] print("Lists content: ", hatList) I don't know If I am being stupid but does the del instruction produce a traceback error for line 5 but works for line 6?
  6. S

    Python 'for' loops, 'exp' variable question

    I am wondering what meaning the 'exp' variable in the 'for' loop. On my course I am taking it says it is a 'control variable' but I am struggling to comprehend what that means?
  7. S

    Python Why doesn't this output "three" as well?

    I am wondering why this only outputs "one" and "two" but not three since elif statements condition is met. Thank you in advance :) x = 1 y = 1.0 z = "1" if x == y: print("one") if y == int(z): print("two") elif x == y: print("three") else: print("four")
Back
Top Bottom