473,385 Members | 1,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

RE: Use of the "is" statement

Maric Michaud wrote:
Le Friday 27 June 2008 18:26:45 Christian Heimes, vous avez écrit*:
>Ask yourself if you are interested if f.tell() returns exactly the
same 0 object ("is") or a number that is equal to 0 ("==").
That said, "f.tell() == 0" and "f.tell() != 0" should be written
"f.tell()" and "not f.tell()" in python.

if not f.tell() :
print 'at the beginning of the file"
No, because semantically you're not using the result of f.tell() as a boolean value. tell() returns a *position*, and he is checking for a particular position.

If he'd instead been testing for f.tell() == 2, would you have advisd that he use "if f.tell()"?

Ignoring the triviality of the below code, would you suggest refactoring:

for i, v in enumerate(iterable):
if i == 0:
doSomethingSpecial()
else:
print i

as:

for i, v in enumerate(iterable):
if not i:
doSomethingSpecial()
else:
print -i

?

Tim Delaney
Jun 30 '08 #1
0 709

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Stefan Strasser | last post by:
why is delete an expression and not a statement? (in my draft copy of the standard). I was about to ask the same question about "throw" but found an expression case of throw("return boolvalue ? 5...
4
by: Tina | last post by:
This is an issue regarding what exactly is accomplished by using "Protected" when defining a variable. It seems it does much more than just applying Protected status to a variable. I have an...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
94
by: Samuel R. Neff | last post by:
When is it appropriate to use "volatile" keyword? The docs simply state: " The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock...
8
by: arnuld | last post by:
my friend sent me this programme: #include<iostream> int main() { int a=5; std ::cout << ++a << "\t" << ++a <<
0
by: Christian Heimes | last post by:
Joel Corbin wrote: As I said: The "is" statement should only be used when you want to check of something is exactly and identical to None like "a is None" or "b is not None". For everything...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.