0

I just realised something about arrays in python, I don't know if it would translate to other languages though.

Here is the thing I realised : Array = ["One","Two","Three"] print(Array) #Appending in a array like this doesn't require us to Again Assign Array.append to the variable Array using the statement{ Array=Array.append(<Value>) } Array.append("Four") print(Array) Please tell me if the same is applicable in other languages like C++, Kotlinas, R, JS, etc as well.

18th May 2024, 7:19 AM
Yash Thale
Yash Thale - avatar
5 Antworten
+ 3
Yes in the languages you mentioned there is similar method used to achieve the same result.
19th May 2024, 10:13 PM
Chris Coder
Chris Coder - avatar
+ 4
Please only put relevant tags in the tag section. Adding a code snippet doesn't work nor help others. https://sololearn.com/compiler-playground/W3uiji9X28C1/?ref=app
18th May 2024, 12:25 PM
Ausgrindtube
Ausgrindtube - avatar
+ 3
There are two possible ways to change a data structure or object. 1. If the object is mutable (changeable), it can have methods which modify some part of it. For example the Python list (do not call it an "array") has methods like sort, append, extend, insert that do in-place modification. numbers = [1, 3, 4, 2] numbers.sort() # then numbers changes to [1, 2, 3, 4] 2. There are also functions which take a data structure as argument, and return a new object that must be assigned to a variable. ordered_numbers = sorted(numbers) # in this case, numbers list is not changed, # the sorted list is assigned to a new variable In other languages you can have similar logic. There are some languages which put bigger emphasis on immutable data structures, such as Kotlin. So it can vary in each case.
21st May 2024, 5:06 AM
Tibor Santa
Tibor Santa - avatar
+ 2
It is not clear what you realized, can you explain in more detail?
18th May 2024, 7:02 PM
Chris Coder
Chris Coder - avatar
+ 1
Chris Coder Sorry for that, Actually it didn't get pasted in the right way. Array = ["One","Two","Three"] print(Array) #Appending in a array like this doesn't require us to Again Assign Array.append to the variable Array using the statement{ Array=Array.append(<Value>) } Array.append("Four") print(Array)
19th May 2024, 1:16 PM
Yash Thale
Yash Thale - avatar