String methods in Python are easy 🧵
Вставка
- Опубліковано 13 чер 2024
- #Python #string #methods
00:00:00 useful string methods
00:08:05 exercise
name = input("Enter your name: ")
phone_number = input("Enter your phone #: ")
length = len(name)
index = name.find(" ")
name = name.capitalize()
name = name.upper()
name = name.lower()
result = name.isdigit()
result = name.isalpha()
result = phone_number.count(" ")
phone_number = phone_number.replace("-", "")
# -------------------------------
# STRING METHODS
# -------------------------------
# name = input("Enter your name: ")
# phone_number = input("Enter your phone #: ")
# length = len(name)
# index = name.find(" ")
# name = name.capitalize()
# name = name.upper()
# name = name.lower()
# result = name.isdigit()
# result = name.isalpha()
# result = phone_number.count(" ")
# phone_number = phone_number.replace("-", "")
# -------------------------------
# EXERCISE
# -------------------------------
username = input("Enter a username: ")
if len(username) > 12:
print("Your name can't be more than 12 characters")
elif not username.find(" ") == -1:
print("Your username can't contain spaces")
elif not username.isalpha():
print("Your username can't contain digits")
else:
print(f"Welcome {username}!")
info1 = print("your username has to be between 3 and 12 characters long!")
info2 = print("your username cant contain spaces and digits!")
username = input("Please enter your username: ")
if username.isdigit() or not username.isalpha():
print(f"{username} is not a valid username!")
elif len(username) = 13:
print(f"{username} is not a valid username!")
else:
print(f"Welcome {username}!!!")
this is how I did it, thx for the tutorials man
I used .isalpha to check for spaces:)
Every programming language is easy when explained by bro😎
did you quit sir?
@@Lit35 Dude do you need help?
@@enespinar9711 i quit and started Roblox scripting lol but i might come back. I hate when you learn smth new u eventually quit. Bro dont be like me just keep going
Very true
_Brooo.._ 😎
Hi Bro, Your HTMl, CSS and Javascript course is mind-blowing
This is THE BEST video about string methods on internet..... THE BEST>>>>>> Excellent..It made me understand everything about string methods...... Thankk you Sir...
You're the first person where I was able to solve the exercises at the end, I feel really proud of myself, thanks
I love when you implement Exercises in your Videos! Im new to programming and love solving these on my own ;P like for example i checked for numbers using isdigit insead of isalpha but it still worked. Keep up the good work
extremely well explained.,.,thanks for your effort
watching your videos as part of my revision :)
thank you for explaining this so well!
You're great man, i'm enjoying a lot this course
Thanks a lot brother code
age = float(input('ENTER YOUR AGE: '))
if age >= 18:
b = input('ENTER YOUR USERNAME: ')
name= len(b)
if name > 12:
print('YOUR USERNAME IS MORE THAN 12 LETTERS')
elif b.count(' ') > 0 :
print('YOUR USERNAME CONTAINS A SPACE')
elif b.isdigit :
print('YOUR USERNAME CONTAINS A DIGIT')
else:
print(f"YOUR USERNAME IS SET TO '{b}' ")
else:
print('YOU MUST BE 18+ TO SIGN UP')
So helpful, thank you!
NICELY DONE BRO...❤
thanks Bro
Your vids are incredibly helpful. How do you find or think of these practice programs?
thanks bro
U R AWESOME
nice exercise
Nice bro code
I love how you include exercises in your videos .But i actually used this code in the exercise:
print('Username must not contain more than 12 letters')
print('Must not contain spaces')
print("And must not contain any digit")
print('')
user_n = input("Enter a username--")
len(user_n)
if len(user_n) > 12:
print("Invalid username as it has too many chracters.")
elif user_n.count(" ") != 0:#can/should also use user_n.find(" ")
print(f"Invalid username as it contains {user_n.count(" ")} space/s.")
elif user_n.isalpha() != True:
print(f"Invalid username as it has a digit/s.")
else:
print("Valid Username !You can sign up...")
This also works but one in the video is better
i love bro
What if I'm typing in spaces AND number, it only show "Your username cannot contains spaces" but not both
OMG I`M THE 100TH LIKE
Hi
can you explain how to write a PID code for Spike prime Robot?
thank you
x = input("Nickname: ")
while len(x) > 12 or len(x) == 0 or x.isalpha() == False:
print("cant be more then 12 characters and cant contain spaces and cant contain digits")
x = input("Nickname: ")
print("Hi!", x.capitalize())
Will you make a tutorial series on Kotlin or teach Android development without Android studio please big bro?? I am not able to use Android studio in my low end pc and would love to learn Kotlin from you :)
3rd commmmment
Bro or Sir please upload REACTJS tutorial
what playlist this video in?
BRO CODE . JS, TS , Nodejs videos please
nice ved :)
chad
but why it become -1 for cant contain any space
2nd comment
I did mine but i only used AND operators
Hello Everyone! My take on it is:
username=input(print("Enter Username:"))
if len(username)>12 or username.find(" ")>=0 or not username.isalpha():
print("Wrong username! It CANNOT:
* be more than 12 characters
* contain spaces
* contain numbers ")
else:
print(f"Welcome {username}!")
Bro, change username=input(print("Enter Username:")) to username=input("Enter Username:"), exlcude the "print" and try again.
I think your code is wrong. What if the username contains a special symbol like "$" - it returns "can't contain digits" but this is not in the conditions
09:17: Why this code needs to have a 'f' string behind "Welcome {username}")? While the others dont?
f string is for inserting variable in a string inside of {}
@@AbhayRajKarun f string is top
I’m the last you can do:
def check_username(username);
If len(username) > 12:
print(“Your username can’t be more than 12 characters “)
elif not username.find(“ “) == -1:
print(“Your username can’t contain spaces!”)
for i in username:
If type(i) == int:
print(“Your username can’t contain numbers”)
why it contain the spaces so it become -1??
.isdigit looks in a str for int and returns a bool 🤔🤨😵💫
Can someone explain why did he used == -1 in 10:54
if you watched the whole video through he explained that if theres no such char found it returns -1
So now i know how these stupid websites program me to enter a password with letters and numbers
well actually, you might wanna look for the html tutorial
name = input("what is your name: ")
name = name.title()
sub1 = len(name)
if sub1 >=10:
print("name is grater then 10")
else:
print("hello," + name)
age = int(input("how old are you: "))
if age >=100:
print("how are you even alive")
elif age
I read a few codes that the commentators and realized that my code is shit
name = input("Enter your username:" )
if len(name) > 12:
print (f"Your username is too long")
elif name.isdigit():
print (f"{name} is not valid symbols")
elif not name.isalpha():
print (f"{name} is not valid symbols")
else:
print(f"Hello {name}!")
why didn t bro just replace input with bro code
readability
def main():
name = input("Type a Name #: ")
z= filter(name)
print(z)
def filter(x):
if len(x) > 12:
return("Name can't be more than 12 characters")
elif not x.find(" ")==-1:
return("Name can't have any spaces")
elif not x.isalpha():
return("Name can't contain numbers")
else:
return (f"Your Name is {x}")
main()
u still programming?
name = input("type name ")
if len(name) > 12:
print("type less bykvi blyaat")
elif name.find("suka") != -1:
print("ne pishi suka, suka")
elif not name.isalpha():
print("dont use digits suka")
else:
print(f"hello {name} suka ")
username = input("what is your username: ")
num1 = len(username)
if num1 >12:
print("this username can only be 12 letters long ")
elif not username.find(' ') == -1:
print("username invalid due to space lease fix it")
elif not username.isalpha ():
print("username can not cointain digits")
else:
print(f"Hello, {username}
hey @BroCode so here is what i wrote when we did the exercise:
username = input("Enter a username: ")
usernamechar = username.count("")
usernamevalid = username.isalpha()
if usernamechar > 12:
print(f"Username: {username} is not a valid username")
elif not usernamevalid:
print(f"Username: {username} is not a valid username")
else:
print(f"Username: {username} is valid")
It worked just fine for me and i was wondering if there may be any sort of reason to use this instead of your way.
its more readable
Bro.isGigaChad()
#true
def checknum(text):
for i in text:
if i.isnumeric():
return False
else:
return True
username = input('enter username: ')
if len(username)
print("Your username should be less than 12 / should not contain spaces! / should not contain digits.")
username = input('Input ur username: ')
if len(username) < 12 and username.isalpha():
print('welcome bro')
else:
print("Your username should be less than 12 / should not contain spaces! / should not contain digits.")
Added a password feature
print("Enter your username.")
name = input(": ")
if len(name) > 12:
print("Username cant contain more then 12 characters")
if name.find(" ") >= 0:
print("Username cannot contain spaces")
elif not name.isalpha():
print("Username cannot contain digits")
else:
print("Just remember that your password must meet the requirements.")
print("-Min 8 characters")
print("-Must contain digits")
print("-Cannot contain spaces")
print("Now please enter you password.")
password = input(": ")
if len(password) < 8:
print("Your password is too short!")
elif password.isalpha():
print("Your password must contain at least one digit!")
elif not password.find(" ") == -1:
print("Your password cannot contain spaces!")
else:
last = password[-2:]
print(f"Hey {name.upper()}, welcome to the club!")
print(f" Your password is XXXX-{last}")
lastmess = "you have succesfully singed up!!!"
print(lastmess.upper())
username = input("Enter a username: ")
username.find(" ")
if len(username) > 12:
print("Your username cannot be more than 12 characters")
elif not username.find(" ") == -1:
print("Your username cannot contain spaces")
elif not username.isdigit():
print("Your username cannot contain digits")
else:
print(f"Welcome {username}!")
why cant we simply use not name.find(" ")
@@RahulSingh-xd4qj .find doesnt return bool
Hey, in 10:20 why I cannot use :
elif username.find(" ") == 1: