x = [ ]
a = abc
b = 3
x.append(a,b)
print(x)
Results
[(abc,3), (def.4)....]
As the value of a.b changes like this, how can I keep it in ( ) as shown in the results?
I'm sorry it's hard to understand, but please let me know.
Additional note
date:
a
12345
1234
b
123456
1234
c
1234567
1234
for such a date
After recognizing ">", add a to x=[ ]
After loading the 12345 line, continue with x=[] and
I want to continue with x=[(a, 9), (b, 10), (c, 11)...]
In this case, once I recognize an empty line, I think I should activate def.
It doesn't work out the way I want it to.
Please give me some advice.
Based on what is stated in the results section, answer the question as if you want the a
and b
pairs (also known as tuples or tuples) to be included in the list.
In that case, you can:
def append_tuple(x,a,b):
t=(a,b)#tuple
x.append(t)
# You can also write x.append(a,b)) above.
defmain():
x = [ ]
append_tuple(x, "abc", 3)
append_tuple(x, "def", 4)
print(x)#=> [('abc', 3), ('def', 4)]
if__name__=="__main__":
main()
© 2024 OneMinuteCode. All rights reserved.