Be sure to like, share and comment to show your support for our tutorials.
Playlist For This Tutorial –
Latest Video –
Length Built-in Function and Python Strings
In this tutorial, we are going to look at the length built-in function and Python strings. This will be a short tutorial there really is not much to find a length of a string. Why would we want to have a length of a string? Say you want to put a minimum number of characters on a string for a user’s password or username. Using len() built-in function would allow us to find the length of the string if the username or password is long enough we will allow them to use the username or password. Of course, there other reasons why you may need to find the length of a string.
Xem thêm bài viết khác: https://vinhtrinh.com.vn/cong-nghe/
I know these where created a few years ago but i also used a loop in the function
username = input('please enter username, min 4 characters: ')
password = input('please choose a password, min of 6 characters: ')
if len(username) < 4 or len(password) < 6:
print('your username or password is not long enough please check and try again')
print('your username and password has been set')
Can you help me with this error! Please
apples-MacBook-Pro-2:desktop apple$ python password.py
Your username? Min 4 characters. Tommy
Traceback (most recent call last):
File "password.py", line 1, in <module>
username = input('Your username? Min 4 characters. ')
File "<string>", line 1, in <module>
NameError: name 'Tommy' is not defined
your the first person of about 30 python tutorial videos I have actually seen explain why the fuck you would use the "len" function. Every other video is like "hey look at what such and a such a function can do!" without showing real world examples of why the hell you would learn all the syntax. Are there any other uses for the len function. I am just trying to think what else it could be used for aside from checking that a user enters in a minimum number of characters for a password. Thanks!