Does the str() function in Python will take all types of objects as parameters or only the Strings? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Does the str() function in Python will take all types of objects as parameters or only the Strings?

>>> str("hello") 'hello' >>> str([1,2,3]) '[1, 2, 3]' >>> str({1,2,"hello"}) "{1, 2, 'hello'}" what does it doing here?

25th Nov 2017, 2:43 AM
sai chander
sai chander - avatar
1 Answer
+ 5
str() turns stuff into strings. So [1, 2, 3] becomes '[1, 2, 3]' and {1, 2, 3} becomes '{1, 2, 3}'. 😉
25th Nov 2017, 3:46 AM
blackcat1111
blackcat1111 - avatar