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

    Sorry to bug you with more questions but I am quite curious. myList = [] # creating an empty list for i in range(5): myList.insert(2, i + 1) print(myList) If I do it this way it outputs [1, 2, 5, 4, 3] Is this because it's just printing every value up until it reaches 5 then the only...
  5. S

    Python insert() function printing the list the opposite way

    I didn't even think about it like that! thank you!!
  6. S

    Python insert() function printing the list the opposite way

    [5, 4, 3, 2, 1] Idk if this helps but this is the output. I am confused why it produces 5 and counts down, I would have thought it would start at 1 and move up?
  7. 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?
  8. S

    Python Simple confusion for the del instuction

    Sorry, I didn't notice that the them being the wrong way round! thank you for telling me. Also your fix with the mix up in the int and input has fixed the issues. It works for either '[4]' or '[-1]'. According to my python course -1 isn't invalid because negative values i.e. [-1] starts from...
  9. 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?
  10. S

    Python 'for' loops, 'exp' variable question

    I apologise I should have added it, you are right as I managed to figure it out eventually. Thank you for your reply!
  11. 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?
  12. S

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

    Thank you both very much, that was highly useful!
  13. 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