bartonc 6,596
Recognized Expert Expert
By that I mean they stop evaluation at the first True part of the expression.
I use it often to replace an uninitialized object. Like this: -
>>> aString = ""
-
>>> aString or "Hello, world"
-
'Hello, world'
-
>>> anObject = None
-
>>> anObject or range(5)
-
[0, 1, 2, 3, 4]
-
>>> anObject = dict(a=1)
-
>>> anObject or range(5)
-
{'a': 1}
-
>>>
5 2034
This has other uses aswell. -
>>> 1 == 2 and "True value" or "False value"
-
'False value'
-
>>> 1 == 1 and "True value" or "False value"
-
'True value'
-
>>> 1 == 1 and "" or "The 'True' value must evaluate to True" # or perhaps not?
-
"The 'True' value must evaluate to True"
-
>>> 1 == 2 and "The 'False' value does not." or ""
-
''
-
>>>
-
Not that this is anything anyone uses often. But its nice to know.
bvdet 2,851
Recognized Expert Moderator Specialist
It is sometimes useful for function defaults: - def polarEllipse(a, res, quad=1, xAxis=False, yAxis=False, rot=0):
-
-
xAxis = float(xAxis or a.Ra)
-
yAxis = float(yAxis or a.p1.dist(a.p3))
-
..........
Motoma 3,237
Recognized Expert Specialist
Good tip. Did you mean for this to be an Article?
bartonc 6,596
Recognized Expert Expert
Good tip. Did you mean for this to be an Article?
Shhhh... That's my secret to high post counts: Publish in the forum, get lots of replies, then decide it should be an article and copy it there.
bartonc 6,596
Recognized Expert Expert
It is sometimes useful for function defaults: - def polarEllipse(a, res, quad=1, xAxis=False, yAxis=False, rot=0):
-
-
xAxis = float(xAxis or a.Ra)
-
yAxis = float(yAxis or a.p1.dist(a.p3))
-
..........
Very useful!
I'm currently reading data from an RDBMS and storing to legacy text files (ongoing support for the predecessor of my project). The database may have empty fields, which are returned as None. The text file needs empty strings. So: -
>>> field1 = None
-
>>> field2 = None
-
>>> ", ".join([str(field1 or ""), str(field2 or "")])
', ' -
>>> field2 = 7.6
-
>>> ", ".join([str(field1 or ""), str(field2 or "")])
-
', 7.6'
-
>>>
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Arnaud |
last post by:
Hi,
I work with php 4.3.4 and I don't understand the way php sort this array for
example :
<?
$array = (-1, 30, "test", true);
sort($array);
var_dump($array);
?>
|
by: Brandon J. Van Every |
last post by:
I'm realizing I didn't frame my question well.
What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump
up in your chair and scream "Wow! Ruby has *that*? That is SO FRICKIN'
COOL!!! ***MAN*** that would save me a buttload of work and make my life
sooooo much easier!"
As opposed to minor differences of this feature here, that feature there.
Variations on style are of no interest to me. I'm coming at this from a...
|
by: anders thoresson |
last post by:
Is it possible to resort the rows in a table like in a query where using
ORDER BY, but have to new sort order stored in the table structure?
--
anders thoresson
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=mysql@freebsd.csie.nctu.edu.tw
|
by: Matt |
last post by:
I have 2 questions:
1. strlen returns an unsigned (size_t) quantity. Why is an unsigned
value more approprate than a signed value? Why is unsighned value less
appropriate?
2. Would there be any advantage in having strcat and strcpy return a
pointer to the "end" of the destination string rather than returning a
|
by: Rennie deGraaf |
last post by:
In the last few days, I have discovered two "interesting" behaviours of
the C language, both of which are apparently correct. Could someone
please explain the reasoning behind them?
1. The operators '^', '&', and '|' have lower precedance than '==',
'!=', '>=", etc. I discovered this when the statement "if (array1 ^
array2 == 0xff)" failed to do what I expected. To me, it doesn't
make any sense to give the bitwise operators lower...
| |
by: Peter S. Guild |
last post by:
Hello,
I have a simple routine that uses a dataview to hold information. I need to
sort these columns by section and then by desc. No matter what I do the
dataview will not sort.
What am I doing wrong?
Language is C#
..Net framework is 1.1
|
by: ano |
last post by:
Hi,
I have converted this VB code to C# but I got this error:
"Operator '||' cannot be applied to operands of type 'int' and 'short'"
Is VB allow to use Operator "Or" with 'int'?
If yes, how to do this in c#?
Thanks,
|
by: Howie |
last post by:
This must be a permissions issue. But I don't know how to fix it.
I am in the middle of writing a database so I haven't even
learned how to deal with security yet.
Could someone tell me how to stop "sort ascending" in a table
being greyed-out? Much appreciated.
Thanks.
--
Pontins History E-Mail: usenet@pontinshistory.co.uk
Please visit www.pontinshistory.co.uk
|
by: ronnysaid |
last post by:
Hello,
Is there a way to get Excel 2007 "sort by" value from a cell range??
to be more clear, if column header is country and you sorted cell range (A1,A10) by country, is there a way to get "country" using C#???
Thanks.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |