How can I change the data type to string in Python?

0 votes
I am writing a program to check the occurence of an alphabet. Here i got stuck on the datatype. Can someone help me with changing of data type to string?
Dec 17, 2018 in Python by Anjali
• 2,930 points
52 views

1 answer to this question.

0 votes
You can use

str(variablename)

This is called conversion in Python. You can use this to convert your variable to type string. Then again it won't work properly in versions <3.0 as if your objects ascii code is more than the ascii of the character then you will get an error, In that case you should use

unicode(variablename)

In version >=3.0 it is taken automatically
answered Dec 17, 2018 by Shuvodip

Related Questions In Python

0 votes
1 answer

How can I change the iteration variable inside a for loop in python?

Assume you have a list of lists: my_list ...READ MORE

answered Jun 10 in Python by Shubham Bansal
46 views
+2 votes
6 answers

How can I change directory or "cd" in Python?

Context Manager: cd import os class cd:     """Context manager for ...READ MORE

answered Oct 18, 2018 in Python by Nabarupa
135 views
0 votes
1 answer

How can I compare the content of two files in Python?

Assuming that your file unique.txt just contains ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,720 points
150 views
0 votes
1 answer

How can I find out the index of an element from row and column in Python?

You probably want to use np.ravel_multi_index: [code] import numpy ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,720 points
96 views
+4 votes
6 answers
0 votes
1 answer

Removing surrounding whitespace

Try the strip() function:  s = s.strip() If you ...READ MORE

answered May 4, 2018 in Python by Nietzsche's daemon
• 4,260 points
47 views
0 votes
1 answer
+2 votes
3 answers

How can I play an audio file in the background using Python?

down voteacceptedFor windows: you could use  winsound.SND_ASYNC to play them ...READ MORE

answered Apr 3, 2018 in Python by charlie_brown
• 7,720 points
2,185 views