What is the tostring() equivalent in Python

6 Answers

0 votes
n = 15

s = str(n)

print(s, type(s))




'''
run:

15 <class 'str'>

'''

 



answered Apr 13, 2021 by avibootz
0 votes
lst = [1, 2, 3, 4]

lst = str(lst)

print(lst, type(lst))




'''
run:

[1, 2, 3, 4] <class 'str'>

'''

 



answered Apr 13, 2021 by avibootz
0 votes
lst = [1, 2, 3, 4]

lst = "{}".format(lst)

print(lst, type(lst))




'''
run:

[1, 2, 3, 4] <class 'str'>

'''

 



answered Apr 13, 2021 by avibootz
0 votes
n = 15
 
s = "{}".format(n)
 
print(s, type(s))
 
 
 
 
'''
run:
 
15 <class 'str'>
 
'''

 



answered Apr 13, 2021 by avibootz
0 votes
n = 15
 
s = f'{n}'
 
print(s, type(s))
 
 
 
 
'''
run:
 
15 <class 'str'>
 
'''

 



answered Apr 13, 2021 by avibootz
0 votes
lst = [1, 2, 3, 4]
 
lst = f'{lst}'
 
print(lst, type(lst))
 
 
 
 
'''
run:
 
[1, 2, 3, 4] <class 'str'>
 
'''

 



answered Apr 13, 2021 by avibootz

Related questions

1 answer 129 views
1 answer 92 views
1 answer 131 views
4 answers 283 views
1 answer 194 views
1 answer 156 views
1 answer 81 views
...