Python Forum
Checking for an item in a list (if then statement)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Checking for an item in a list (if then statement)
#1
I am very new to python. I am trying to check if the first letter of a word is a vowel or not and I have to do so using sets. Here is what I am trying but it isn't working.

My_Word = "cat"
First_Letter = My_Word[0]
vowels = {'a', 'e', 'i', 'o', 'u'}
if First_Letter in vowels == true
From there I get a syntax error. Any help?

Got it... there was a ":"

Go figure
Reply
#2
The == true at the end of line 4 is redundant. That is, that line is more naturally written

if First_Letter in vowels:

which also reads quite nicely.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Checking if a string contains all or any elements of a list k1llcod3 1 1,095 Jan-29-2023, 04:34 AM
Last Post: deanhystad
Question Finding string in list item jesse68 8 1,862 Jun-30-2022, 08:27 AM
Last Post: Gribouillis
  List Creation and Position of Continue Statement In Regular Expression Code new_coder_231013 3 1,662 Jun-15-2022, 12:00 PM
Last Post: new_coder_231013
  how to easily create a list of already existing item CompleteNewb 15 3,527 Jan-06-2022, 12:48 AM
Last Post: CompleteNewb
  Remove an item from a list contained in another item in python CompleteNewb 19 5,691 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  Change a list to integer so I can use IF statement buckssg 3 2,234 Sep-21-2021, 02:58 AM
Last Post: bowlofred
  count item in list korenron 8 3,443 Aug-18-2021, 06:40 AM
Last Post: naughtyCat
  How to invoke a function with return statement in list comprehension? maiya 4 2,825 Jul-17-2021, 04:30 PM
Last Post: maiya
  checking for last item in for loop Skaperen 11 4,238 Jul-09-2021, 11:40 PM
Last Post: Skaperen
  An IF statement with a List variable dedesssse 3 8,210 Jul-08-2021, 05:58 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020