Results 1 to 3 of 3

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

  1. #1
    Join Date
    May 2007
    Location
    Canada!
    Beans
    1,709
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    [SOLVED] basic python question - check if a string contains some text?

    I am aware that in bash you can go
    Code:
    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
    Code:
    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

  2. #2
    Join Date
    Oct 2007
    Beans
    140

    Re: basic python question - check if a string contains some text?

    Code:
    var = "value"
    if "value" in var:
        print "True"
    Do you mean that?

  3. #3
    Join Date
    May 2007
    Location
    Canada!
    Beans
    1,709
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: basic python question - check if a string contains some text?

    with the exception of the fact that "var" will be ever changing user input, I believe this will do quite nicely

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •