Python Forum
Using if statement without object
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using if statement without object
#1
Hello all,

I've been using PowerShell for years but am brand new to Python. I'm trying to figure out if I can use an If statement without a specifically defined variable. For instance, the following throws an error:

import re

If re.match("he","hellostring")):
    print("match!")
In PowerShell, I could use the $() special operator to cast a statement as a variable, and I'm wondering what I need to do to make the above If statement work, or if i need to assign the re.match() statement to a variable and then put the variable in the If statement?

Apologies for any errors in this post's format, my first one on this site. Big Grin
Reply
#2
Why should the statement work? You're writing If instead of if and there is an extra closing parenthesis...
Reply
#3
Doh

Totally missed the extra parenthesis, and apparently I'm still getting used to case-sensitive languages. Thanks!
Reply


Forum Jump:

User Panel Messages

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