Python Forum
Using if statement without object - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Using if statement without object (/thread-12501.html)



Using if statement without object - vv0bbLeS - Aug-27-2018

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


RE: Using if statement without object - Gribouillis - Aug-27-2018

Why should the statement work? You're writing If instead of if and there is an extra closing parenthesis...


RE: Using if statement without object - vv0bbLeS - Aug-28-2018

Doh

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