473,498 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using the or operator in python

kaarthikeyapreyan
107 New Member
How does the python interpreter work for the or operator
cause i am a bit confused with its output

Expand|Select|Wrap|Line Numbers
  1. >>> s= "unbound method __delitem__() must be called with _Environ instance as first argument (got str instance instead)"
  2. >>> 
  3. >>> if "least" in s:
  4. ...   print "hi"
  5. ... 
  6. >>> if "least" or "exactly" in s:
  7. ...   print "hi"
  8. ... 
  9. hi
  10. >>> if "exactly" in s:
  11. ...   print "hi"
  12. ... 
  13. >>> 
  14.  
Jun 16 '08 #1
1 5017
jlm699
314 Contributor
Python's [or] is not much different from or in other languages. It simply returns the first "True" operand that it is passed. In your case you're using it wrong, because to Python, an empty string is False. As soon as a string has any non-null value it is true. So by saying "least" or "exactly" it will return the first true operand (least).

To use it the way you are attempting you should have the following:
Expand|Select|Wrap|Line Numbers
  1. if "least" in s or "exactly" in s:
  2. ...  print hi
  3.  
Jun 16 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2188
by: Roy Smith | last post by:
Up until recently, Python was the only language I'd ever seen that used the % operator for string replacement. Today, I was perusing the C++ Boost libraries, and discoverd that boost::format uses...
1
1676
by: Andrew Wilkinson | last post by:
Hi, This is probably more of a gcc question than a python one, but hopefully someone out their will know that answer. I've written a C++ Python extension, and as part of it I override the...
9
4588
by: mathias | last post by:
I would like to define a custom operator in Python. (It is not about overloading an existing operator but about defining special new operators) Is this possible without deeply manipulating the...
0
1714
by: Michael Spencer | last post by:
Wow - Alex Martelli's 'Black Magic' Pycon notes http://www.python.org/pycon/2005/papers/36/pyc05_bla_dp.pdf include this gem: > Functions 'r descriptors > def adder(x, y): return x + y > ...
6
3800
by: praba kar | last post by:
Dear All, I am new to Python. I want to know how to work with ternary operator in Python. I cannot find any ternary operator in Python. So Kindly clear my doubt regarding this ...
9
1605
by: Lonnie Princehouse | last post by:
There doesn't seem to be any way to customize the behavior of "is" as can be done for other operators... why not?
2
1871
by: Martin v. Löwis | last post by:
I've been working on PEP 353 for some time now. Please comment, in particular if you are using 64-bit systems. Regards, Martin PEP: 353 Title: Using ssize_t as the index type Version:...
1
7462
by: asdsd sir | last post by:
Hi!I'm new in Python and i'd like to ask some general questions about stdin,stdout... Firstly... if we type like something like : cat "file.txt"|python somefile.py #somefile.py import sys
5
2486
by: cjt22 | last post by:
Hi there I am fairly new to Python and have not really used regular expressions before (I think this might be needed for my query) and wondered if you could help I have a step class and store...
19
3493
by: C++Liliput | last post by:
I have a custom String class that contains an embedded char* member. The copy constructor, assignment operator etc. are all correctly defined. I need to create a map of my string (say a class...
0
7167
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7208
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5464
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4915
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4593
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3095
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.