pkdata1026
pkdata1026

Reputation: 73

Check if string contains specific character

my_string = "wolfofwalstreet(2012)is a movie"

Need to run python script to check if it contain the character: bracket

"("

Upvotes: 5

Views: 17040

Answers (3)

Alex_P
Alex_P

Reputation: 2952

This code will give you the index of the character been found.

my_string = "wolfofwalstreet(2012)is a movie"

result = my_string.find('(')
print("Found", result)

If the character is not found, you receive an '-1'.

As described by the answers below, you can of course but it in an IF-statement.

Upvotes: 4

Sarath Raj
Sarath Raj

Reputation: 139

hi you can check by this way:

my_string = "wolfofwalstreet(2012)is a movie"
if '(' in my_string:
    print('yes')
else:
    print('no')

Upvotes: 10

Dmitriy Fialkovskiy
Dmitriy Fialkovskiy

Reputation: 3225

my_string = "wolfofwalstreet(2012)is a movie"
if '(' in my_string:
    print('yes, "(" is in my_string')

Upvotes: 2

Related Questions