Python 2.5 help

This is the place for queries that don't fit in any of the other categories.

Python 2.5 help

Postby toastedPC » Sat Nov 16, 2013 4:35 pm

Hello all, I am running python 2.5 and was trying to set up a conversation that you could have with the program that I set up. Obviously i wouldn't be able to predict every single possible answer so I was going to use else clauses and elif clauses. However, I was wondering if there was a way to "search" the raw_input for a certain word. I know that you can do something similar with .endswith and .startswith but i was hoping that there would be a way to do something like .contains so that it would look for a certain word and execute a certain command if it was found. If you're wondering why I'm using 2.5 it's simply because I already had a book explaining it but it was for that version and I wanted to learn the basics and then make adjustments when I upgraded.
toastedPC
 
Posts: 6
Joined: Sat Nov 16, 2013 4:26 pm

Re: Python 2.5 help

Postby stranac » Sat Nov 16, 2013 4:39 pm

I'm pretty sure that you can use the in keyword:
Code: Select all
>>> 'an' in 'banana'
True
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm

Re: Python 2.5 help

Postby Kebap » Sat Nov 16, 2013 5:20 pm

toastedPC wrote:If you're wondering why I'm using 2.5 it's simply because I already had a book explaining it but it was for that version and I wanted to learn the basics and then make adjustments when I upgraded.

Hi and welcome! I would suggest you use 2.7 because this is still actively developed whereas 2.5 is not. It is also very compatible to 2.5, unlike the python versions 3.*
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 396
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: Python 2.5 help

Postby toastedPC » Sun Nov 17, 2013 12:11 am

stranac wrote:I'm pretty sure that you can use the in keyword:
Code: Select all
>>> 'an' in 'banana'
True

so would I just type
Code: Select all
if 'an' in 'banana' == True: print 'example'
toastedPC
 
Posts: 6
Joined: Sat Nov 16, 2013 4:26 pm

Re: Python 2.5 help

Postby stranac » Sun Nov 17, 2013 12:14 am

No need for the == True
Code: Select all
if 'an' in 'banana':
    print 'example'
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm


Return to General Coding Help

Who is online

Users browsing this forum: asadbjs, Bing [Bot] and 4 guests