The difference between {ex)place} being established in one line and {ex)append,dell} being established in multiple lines

Asked 2 years ago, Updated 2 years ago, 22 views

Hello, I'm a student who learned Python for the first time, so I'm going to practice before the semester starts. I don't know the difference between being established in many lines and being established in one line.

a=[12,245,34,23,6,237]

print(a.sort())
"""Why is this NONE???"""

a.sort()
print(a)
c="I'm bored because I didn't start school."
c.replace ("I'm bored.""I'm happy")
print(c)

"""Why can't I apply replace?"""

print (c.replace ("I'm bored." "I'm happy!"))

Does "replace" only exist in one line??"""

In addition, list.append() is only established outside the print, but not inside. Is there a difference between {ex)place} that is established only in one line and {ex)append,dell} that is established in multiple lines?

I have to find it and memorize it.Shall we? Or should I learn a lot from experience or look for it whenever there's an error?

python

2022-09-21 12:13

1 Answers

a=[12,245,34,23,6,237]
print(a.sort()) # None

list.sort() returns nothing after changing the order of the elements in the list. The value of a itself is changed. And since there is no return value, output None.

c="I'm bored because I didn't start school."
c.replace ("I'm bored.""I'm happy")
print(c) # I'm bored because school doesn't start.

str.replace() returns the replaced string. As opposed to list.sort(), c itself does not change and just returns. Therefore, the above code outputs the original value of c.

In this way, each method has its own (not an exact representation) value that the object owns (?...) and does not. If you do not make changes, you usually end up returning the changed values without archiving them.

The way to figure this out is generally (except by writing and memorizing it often):

There is.


2022-09-21 12:13

If you have any answers or tips


© 2025 OneMinuteCode. All rights reserved.