• Register
search
Log In
0 votes
53 views
How to use python tostring?
2.1k points
reopened by

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.
480 points
selected by

Related questions

3 votes
1 answer 11 views
11 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.2k points
1 vote
1 answer 7 views
7 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 11 views
11 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
1 vote
1 answer 7 views
7 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 samhaz 5k points
0 votes
1 answer 13 views
13 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 Gavin 15.2k points