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

Please log in or register to answer this question.

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,
as:

```
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.
3
480 points

Related questions

0 votes
1 answer 15 views
15 views
Problem: I own an extremely huge dataset in the arrangement of an information outline and was figuring how I could part the information outline into two arbitrary examples (80% and 20%) for preparing and testing purposes. many thanks to you ahead of time for your assistance.
asked Dec 24, 2020 sasha 5.3k points
0 votes
1 answer 28 views
28 views asked Oct 23, 2020 Shaad Sh 800 points
0 votes
1 answer 13 views
13 views
I require to remove all the special characters, puntuation and and speces from a string?
asked Sep 14, 2020 Daniel Anderson 4k points
1 vote
1 answer 53 views
53 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, 2020 anonymous
3 votes
1 answer 24 views
24 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, 2020 Gavin 15.3k points
1 vote
1 answer 19 views
19 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, 2020 samhaz 5k points
1 vote
1 answer 50 views
50 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, 2020 samhaz 5k points
1 vote
1 answer 21 views
21 views
Problem: I have OpenSSL installed so I tried to hash some strings in python. So I wrote this code: import hashlib def hash_password(password): def check_password(hashed_password, user_password): password, salt = hashed_password.split(':') return password ... check_password(hashed_password, user_password): ^ IndentationError: expected an indented block Can anyone help me out to solve this thing.
asked Jun 9, 2020 samhaz 5k points
0 votes
1 answer 21 views
21 views
Problem: Hello kodlogs, Recently while attempting, the problem in the python there is a error that came can you please help sort out this problem, How can I get the first character from the first string in Python?,It seems that I could use list[0][1:] but that does not give me the first character of the string that I am looking for. mysrt = "sdf" >>> mystr[0][1:]
asked Jun 6, 2020 Gavin 15.3k points
0 votes
1 answer 38 views
38 views
Problem: Hello Kodlogs, I am a beginner to python and I am having a doubt that how to check if the character is present in the string or not though, I know one method but wondering if any other method is available or not (in operator ) this is the method I am using ... ) print("Check if "+string+" contains "+subchar1+":") print(subchar1 in string) Waiting for a few more method that can help me.
asked Jun 5, 2020 Gavin 15.3k points