Get string length - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Get string length (/thread-5779.html) |
Get string length - RedSkeleton007 - Oct-21-2017 To start off, I just want to print the length of a hard coded string as follows: #!/usr/bin/env python3 #NestedIfStuff.py password = "dink" print(str(password.len()))But I get the error: AttributeError: 'str' object has no attribute 'len' What's wrong? RE: Basic string manipulation - metulburr - Oct-21-2017 you would do it this way print(len(password)) RE: Get string length - RedSkeleton007 - Dec-04-2017 I need to convert user string input to a number. My statement on line 7 isn't working: import itertools import sys alphaNum = 'abc' password = 'cab' guessLength = input("How many characters would you like to guess up to: ") int(guessLength) for x in range(0, guessLength+1): guessList = [''.join(i) for i in itertools.product(alphaNum, repeat = x)] for guess in guessList: if (password == guess): print("the password is " + password) sys.exit() print(guess) What do I need to do?
RE: Get string length - DeaD_EyE - Dec-04-2017 You have forgotten to assign the integer in line 7: guessLength = int(guessLength) |