Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Variable declaration
#1
Suppose, I have a set A={'a','b','c'}. I want to declare variables look like N_a, N_b, N_c for every 'a','b','c' in A. Thanks in advance.
Reply
#2
Why? What are you actually trying to achieve?
Reply
#3
(Mar-05-2021, 04:17 PM)ndc85430 Wrote: Why? What are you actually trying to achieve?
For example, I have a relation looks like- a:- b,c,0.8 (called rule in possibilisitcs answer set programming). I like to transfer this relation into an inequality looks like N_a >= min(N_b,N_c,0.8) where N_a, N_b, N_c are variables. We can do it manually but for 100 or 1000 rules how could do that by machine?
Reply
#4
For such a large number of values, better use a data structure, such as a list.

If positions of values have some meaning, then using list with indexing should do it for you.
Reply
#5
Do you want to generate code or make variables? Making variables isn't very useful because it is easier to keep track of collections of variables than trying to figure out a way to get the correct attribute name. It is easy to make programmatically create a variable named 'N_a', but it is difficult for anyone to know that 'N_a' exists, and even harder to make something like N_a >= min(N_b,N_c,0.8).

When you say "We can do it manually", what do you mean? How are you doing this manually? I know of no way to manually make variables unless I am running an interactive interpreter. I know how to write code that makes variables. I even know how to write code that knows how to write code.
Reply
#6
(Mar-05-2021, 04:10 PM)Asraful_Islam Wrote: Suppose, I have a set A={'a','b','c'}. I want to declare variables look like N_a, N_b, N_c for every 'a','b','c' in A. Thanks in advance.

After you define them, how are you going to use them?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  dynamic variable name declaration in OOP style project problem jacksfrustration 3 717 Oct-22-2023, 10:05 PM
Last Post: deanhystad
  Help in Class declaration KranthiYamanki 1 1,854 May-30-2019, 10:51 AM
Last Post: heiner55
  makingVariable declaration mandatory rohitnirantar 5 2,969 Aug-26-2018, 08:00 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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