PDA

View Full Version : [SOLVED] basic python question - check if a string contains some text?



ryanVickers
January 18th, 2008, 11:23 PM
I am aware that in bash you can go


if [[ $var =~ "value" ]]; then
and this will check for if the variable "var" contains the text "value". How would one go about doing this in python?
so far, I have


if var == value:
but that is of course to check if it is solely equal to it - I want to detect if it contains it :confused:

Mr.popo
January 18th, 2008, 11:33 PM
var = "value"
if "value" in var:
print "True"


Do you mean that?

ryanVickers
January 18th, 2008, 11:49 PM
with the exception of the fact that "var" will be ever changing user input, I believe this will do quite nicely :D