Python Forum
Basic Pyhton for Rhino 6 question about variables
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic Pyhton for Rhino 6 question about variables
#1
Hi all,

I've been trying to create a sequence in which a new value is based on the older value.
then the values change making the new value the old one and create a new value and so on in a for loop.

the problem I'm facing is when assigning a variable to a variable. If a change happens to one variable the other one changes to match the first one

here is a simple and easy example:

pt1 = [1,1,1]
pt2 = pt1
pt1[2] = pt1[2] * 2
print(pt1)
print(pt2)

the result that shows up is as follows:

[1, 1, 2]
[1, 1, 2]

isn't it supposed to be?

[1, 1, 2]
[1, 1, 1]


why did pt2 change after modifying pt1?
is there a way to assign the values of the variable instead of its path?

Thanks to anyone
Reply


Messages In This Thread
Basic Pyhton for Rhino 6 question about variables - by SaeedSH - Jan-28-2020, 03:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Very Beginner question on simple variables Harvy 1 386 Apr-12-2024, 12:03 AM
Last Post: deanhystad
  Basic Coding Question: Exit Program Command? RockBlok 3 717 Nov-19-2023, 06:31 PM
Last Post: deanhystad
  Vlookup function in Pyhton antozas 1 745 Oct-02-2023, 04:16 AM
Last Post: vikraman
  [solved] Basic question on list matchiing paul18fr 7 2,033 May-02-2022, 01:03 PM
Last Post: DeaD_EyE
  Very basic calculator question BoudewijnFunke 4 2,055 Dec-10-2021, 10:39 AM
Last Post: BoudewijnFunke
  Reading Multiple text Files in pyhton Fatim 1 2,019 Jun-25-2021, 01:37 PM
Last Post: deanhystad
  basic question isinstance tames 5 2,961 Nov-23-2020, 07:20 AM
Last Post: tames
  basic question about tuples and immutability sudonym3 6 3,071 Oct-18-2020, 05:11 PM
Last Post: sudonym3
  Pyhton code help from head first with python Shaikat_99 3 3,327 Jun-07-2020, 09:12 AM
Last Post: snippsat
  Question regarding local and global variables donmerch 12 5,399 Apr-12-2020, 03:58 PM
Last Post: TomToad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020