• Register
1 vote


I was tring to find the length of a string in python. So I wrote a code:

string = 0
for c in "popular": 
print (string) 

which gives following error;

File "ab.py", line 3
SyntaxError: invalid syntax

Is this the right way to do this or there are other waysto find this out?

10 7 2
6,060 points

1 Answer

1 vote


To find out the length of a string in python you should have wrote your code as:
string = 0
for c in "popular": 
print (string) 

or you also can use len() method for this :

string = "popular" 

And the both output will be


Happy coding.

11 6 4
34,950 points

Related questions

0 votes
1 answer 16 views
I am new to python programming I was trying to check if a letter is uppercase in python. I wrote some code to check this statement : import string def UpperCase(s_str): for x in s_str: if x not in string.UpeerCase: return False return True But I can not get the actual ... last): File "<stdin>", line 1, in <module> NameError: name 'LoWWE' is not defined Can anyone help me to solve this thing?
asked Mar 14 LizzyM 6.1k points
1 vote
1 answer 26 views
Problem: I am beginner in pyhton prgramming language, I tried to convert string array to int array using python so I wrote a code which contains- testing_list = ['4', '2', '3', '9', '5'] And my code is: testing_list = ['4', '2', '3', '9', '5 ... list is : str(testing_list) Converted list is : str(testing_list) why am I not getting the converted result and what is the way to get the acurate result?
asked Mar 29 LizzyM 6.1k points
2 votes
1 answer 15 views
Problem: Hello all, I am a new student in the Python programming language. I am learning through a textbook. I just completed the String chapter and started solving the problems of this chapter. Some of the problems are easy to solve for me. I stuck on a point ... understand. I&rsquo;ve seen some of the solutions answered by the good people. If anybody could help me would be great for me. Thanks
asked Mar 29 Gavin 15.3k points
1 vote
1 answer 66 views
Problem: I was trying to remove a letter from a string by writing this python program: def removechar(p, q) : counts = p.count(q) p = list(p) while counts : p.remove(q) counts -= 1 print(p) if __name__ == '__main__' : p = "nooneisallinall" removechar(p,'n') And the program ... 'l', 'l', 'i', 'a', 'l', 'l'] How can I get the output as string after removing the specific letter. Thanks in advance.
asked May 16 samhaz 5k points
1 vote
1 answer 34 views
Problem: Hello I am starting my programming experience with python recently. I&rsquo;ve been surfing over the internet for a program that can remove punctuation from a String. I&rsquo;ve found many of them but still can&rsquo;t understand them. I am looking for a program written in very basic codes. If possible, please write me a program which would be easy to understand for me. Thanks
asked Mar 8 Gavin 15.3k points