Well, I can say this is a great idea. I would like to add a bit of extra input on this post. The string method
partition(match_item)
returns a tuple of the input before match_item, the match_item and the string after the match_item. You have a great ability to anticipate user input, which will help with preventing errors and exceptions later in the code.
So what i can say is this can be done in two lines of code. The first line is tuple unpacking. The next line is what you would like returned.
username, _, domain = input("Enter Your Email: ").strip().partition("@")
print(f"Your username is {username} & domain is {domain}")
A more "pythonic" way of doing it is by using functions. Having the variables in the global space in a module can cause errors.
def email_slicer(email):
username, _, domain = email.strip().partition("@")
return f"Your username is {username} & domain is {domain}"
user_input = input("Enter Your Email: ")
print(email_slicer(user_input))
The next step up would be to add some test to your module. Overall pretty good tutorial.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Well, I can say this is a great idea. I would like to add a bit of extra input on this post. The string method
partition(match_item)
returns a tuple of the input before match_item, the match_item and the string after the match_item. You have a great ability to anticipate user input, which will help with preventing errors and exceptions later in the code.
So what i can say is this can be done in two lines of code. The first line is tuple unpacking. The next line is what you would like returned.
A more "pythonic" way of doing it is by using functions. Having the variables in the global space in a module can cause errors.
The next step up would be to add some test to your module. Overall pretty good tutorial.