Is there a way to rename an object, such as Reference & in C++ in Python?

Asked 2 years ago, Updated 2 years ago, 17 views

If the name of the object in C++ is too long

int &z = Group[i].Particle[j].pos[k];
z +=1;
if (z > 0) 
{ ...

Is there a similar function or technique (?) with Python to simplify code in this way??

python

2022-09-22 18:51

1 Answers

You are misunderstanding the & use before the variable in c/c++.

Reference operator, not renaming the object.

[cling]$ int a = 3
(int) 3
[cling]$ int &b = a
(int) 3
[cling]$ b
(int) 3
[cling]$ &b
(int *) 0x7f8ff8970010
[cling]$ &a
(int *) 0x7f8ff8970010
[cling]$ b = 8
(int) 8
[cling]$ a
(int) 8

In Python, you can shorten a long import declaration with the as operator, and you can do it with as to some extent, but there's no such thing as Pascal's with syntax.


2022-09-22 18:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.