• Register
0 votes
How to use python tostring?
13 9 3
2,100 points

1 Answer

0 votes
Best answer
In Python, unlike in JavaScript, or Java, we do not actually have direct function "toString".

You can have it in one or two ways.

1. You can use ```str ( )``` Python function to change/cast the other Python data type to python string,

data = 1234
stringData = str(data)

2. or you can manually make your own function.
You can do so as in below:

```def toString(data):
        return str(data)

That's it.
480 points

Related questions

0 votes
1 answer 6 views
I require to remove all the special characters, puntuation and and speces from a string?
asked Sep 14 Daniel Anderson 4k points
1 vote
1 answer 32 views
I am trying to write a script to print specific words after a particular string. Here is the input file Theyare "playing in the ground", with friends Theyare "going to Paris", with family Theyare "motivating to learn new things", by themselves In the output I am trying to select "are" as the keyword ... open ('input.txt', 'r') as f: for lines in f: a = re.search(r'\bare', f): if a: print (lines)
asked Jul 15 anonymous
3 votes
1 answer 17 views
Problem: Hello kodlogs, Recently while studying the string concept in python was doing the string interview preparation in that the question was about how can we accept the last 2 character of the string so I am bit confused, like how can we achieved this and what are the other way to access the last two character of string.
asked Jun 11 Gavin 15.3k points
1 vote
1 answer 14 views
Problem: For the following string I tried to convert is’s first character to a upper case. So I write a program. The string: forgodsake The program I wrote is: main_str = "forgodsake" print("The main string youput is : " + str(main_str)) key = main_str[0] + ... I am getting is not right. What is the problem in my code, why am I not getting the expected result. Can anyone sort this out?
asked Jun 10 samhaz 5k points
1 vote
1 answer 38 views
Problem: I was trying to check if string contains special characters using a python program. To check this I wrote this code: import re # Function checks if the string # contains any special character def check(string): regex = re.compile('[@_!#$%^&*()<>?/\|}{~:]' ... line 11, in check if(search(string) == None): NameError: name 'search' is not defined How can I solve this problem can anyone help?
asked Jun 10 samhaz 5k points