How can I go about using var == False in Python?

0 votes

Hi all. I know that in Python we can write an if block by using the following piece of code:

var = True
if var:
    print 'Hello Edureka'

But what I really want to know is that, if there is a way which involves doing the opposite, i.e making use of the statement without using the ==

Let me give you an example:

var = False
if !var:
    print 'learnt stuff'

How can I go about doing this? What am I missing here?

All help appreciated!

Feb 13 in Python by Anirudh
• 2,060 points
28 views

1 answer to this question.

0 votes

Hi. Simple answer. 

All you need to do is make use of the negation operator - Not

Consider the following code snippet:

var = False
if not var:
    print 'learnt stuff'

Yes, it is as simple as that. Hope this helped!

answered Feb 13 by Nymeria
• 3,500 points

Related Questions In Python

+2 votes
3 answers

How can I play an audio file in the background using Python?

down voteacceptedFor windows: you could use  winsound.SND_ASYNC to play them ...READ MORE

answered Apr 3, 2018 in Python by charlie_brown
• 7,710 points
1,327 views
0 votes
1 answer

How can I define a multidimensional array in python using ctype?

Here's one quick-and-dirty method: >>> A = ((ctypes.c_float ...READ MORE

answered Oct 9, 2018 in Python by ariaholic
• 7,320 points
209 views
0 votes
1 answer

How can I rename multiple files in a certain directory using Python?

Use os.rename(src, dst) to rename or move a file ...READ MORE

answered Nov 23, 2018 in Python by ariaholic
• 7,320 points
89 views
0 votes
1 answer

How can I use indices in math using python

Operator ^ is a bitwise operator, which does "bitwise exclusive or". More: http://wiki.python.org/moin/BitwiseOperators The ...READ MORE

answered Dec 11, 2018 in Python by ariaholic
• 7,320 points
46 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 132 views
+4 votes
6 answers
0 votes
1 answer

How can I have only positive decimal numbers in Django using Python?

Hi, are you aware of something called ...READ MORE

answered Jan 30 in Python by Nymeria
• 3,500 points
229 views
0 votes
1 answer

How can I lookup hostname using the IP address with a timeout in Python?

Good question. I actually was stuck with ...READ MORE

answered Feb 6 in Python by Nymeria
• 3,500 points
58 views