473,396 Members | 1,785 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,396 software developers and data experts.

Does python support the expression "a = b | 1"???

a = b | 1

a = b if b != nil
else a =1

Is there such expression in python?

Thanks a lot!
Oct 5 '05 #1
4 1712
Wenhua Zhao wrote:
a = b | 1

a = b if b != nil
else a =1

Is there such expression in python?


Soon there will be, but currently: no. What you are after is a ternary
operator like _?_:_ in C. There have been plenty of discussions about
these - search this NG. Depending on your usecase, either

if b is not None:
a = b
else:
a = 1

or

a = [1,b][b is not None]

or even

a = b or 1

will do the trick.

But PLEASE read the discussions first, to understand the reasons and
implications.

Diez
Oct 5 '05 #2
[Wenhua Zhao]
a = b | 1 a = b if b != nil
else a =1 Is there such expression in python?


Hi. Merely write:

a = b or 1

In Python, there is no `nil'. `a' will receive 1 instead of the value of
`b' only if `b' is either zero, None, False, or empty in some way.

--
François Pinard http://pinard.progiciels-bpi.ca
Oct 5 '05 #3
Wenhua Zhao <wh****@gmail.com> writes:
Is there such expression in python?


Not in the current version but one is being added.
Oct 5 '05 #4
On 2005-10-05, Wenhua Zhao <wh****@gmail.com> wrote:
a = b | 1
Yes, Python supports that expression.
a = b if b != nil
else a =1
But that's not what it means.
Is there such expression in python?

b=0
b = 0
a = b | 1
a 1 b = 1
a = b | 1
a 1 b = 2
a = b | 1
a 3


I'm not sure what What you mean by "nil", but I would geuess
this is the equivalent Python:

if b is not None:
a = b
else:
a = 1

--
Grant Edwards grante Yow! .. Do you like
at "TENDER VITTLES?"?
visi.com
Oct 5 '05 #5

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

Similar topics

7
by: Rene Pijlman | last post by:
Section 6.5 "What is delegation?" of the FAQ says: "Python programmers can easily implement delegation. For example, the following class implements a class that behaves like a file but converts...
11
by: tdi | last post by:
Ok, stupid question for the day. I'm reading the interview with Steve Moret and he says: "Once a lot of scripts started going in we knew there was no way we could back out of using Python." I'm...
70
by: Roy Yao | last post by:
Does it mean "(sizeof(int))* (p)" or "sizeof( (int)(*p) )" ? According to my analysis, operator sizeof, (type) and * have the same precedence, and they combine from right to left. Then this...
11
by: Grant Edwards | last post by:
I've read over and over that Python leaves floating point issues up to the underlying platform. This seems to be largely true, but not always. My underlying platform (IA32 Linux) correctly...
206
by: WaterWalk | last post by:
I've just read an article "Building Robust System" by Gerald Jay Sussman. The article is here: http://swiss.csail.mit.edu/classes/symbolic/spring07/readings/robust-systems.pdf In it there is a...
26
by: Frank Samuelson | last post by:
I love Python, and it is one of my 2 favorite languages. I would suggest that Python steal some aspects of the S language. ------------------------------------------------------- 1. Currently...
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...
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...
0
marktang
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,...
0
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.