about str function | Sololearn: Learn to code for FREE!
0

about str function

what is the use of str function in every operation of calculator for example: c=str(a-b) ---------- here the part of str...?

28th Feb 2020, 4:55 AM
Kusum Paliwal
Kusum Paliwal - avatar
3 Respostas
+ 3
It is not a function, it is a string class. Calling str() will call string constructor and create new string instance. str() creates a string format of a value. This is very useful because it helps you to handle values as strings using their string formats, this can also be treated as type conversion to string: str(8) + str(9) = "89" int(str(135)[::-1]) = 531 You can similarly often also convert strings to other types, like integers. There is a very similar function repr, which is often a little faster with almost same result. repr focuses on what a value would look like as a string str focuses on how the value would be converted to a string
28th Feb 2020, 5:05 AM
Seb TheS
Seb TheS - avatar
+ 3
Seb TheS , I'm not a python expert but official documentation says str() is a function ūüėÖ "in particular, practically all objects can be compared for equality, tested for truth value, and converted to a string (with the repr() function or the slightly different str() function)." from 4th paragraph of this page : https://docs.python.org/3/library/stdtypes.html
28th Feb 2020, 5:12 AM
ūüáģūüá≥OmkarūüēČ
ūüáģūüá≥OmkarūüēČ - avatar
+ 3
ūüáģūüá≥OmkarūüēČ technically you are both right, str is a built-in class, so str() is a constructor that returns a string object.
28th Feb 2020, 5:57 AM
Tibor Santa
Tibor Santa - avatar