Which method to check if string index is queal to character.

Bischoop Bischoop at vimart.net
Mon Dec 28 11:31:33 EST 2020


I'd like to check if there's "@" in a string and wondering if any method
is better/safer than others. I was told on one occasion that I should
use is than ==, so how would be on this example.

s = 'this at mail.is'

I want check if string is a valid email address.

code '''
import time

email = "ten at mail.tu"

start_time = time.time()
for i in range(len(email)):
  print('@' in email[i])

print ("My program took", time.time() - start_time, "to run")


print('----------')
start_time = time.time()
for i in range(len(email)):
    print(email[i] == '@')

print ("My program took", time.time() - start_time, "to run")
print('----------')
start_time = time.time()
if '@' in email:
    print('True')

print ("My program took", time.time() - start_time, "to run")

'''


More information about the Python-list mailing list