473,548 Members | 2,704 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

['a', 'b'][True] results 'b' But how?

Hi,

Can any one please tell me how is the following code is working?
['a','b'] is a list of string, and [True] is list of boolean value.
How is it making effect....?
<code Python24>
>>['a','b] [True]
'b'
>>['a','b'] [False]
'a'
>>['a','b']['some_string' == r'some_string']
'b'
>>['a','b']['some_string' == r'somestring']
'a'

<code>
Thanks in advance,
regards,
kath.

Jul 5 '07 #1
2 901
kath wrote:
Hi,

Can any one please tell me how is the following code is working?
['a','b'] is a list of string
Yes.
and [True] is list of boolean value.
No. It's the subscription operator applied to the list of strings.
a = ['a', 'b']
a[True]
may be clearer.
How is it making effect....?
>>int(True)
1
>>int(False)
0
>>isinstance(Tr ue, int)
True
>>bool.__bases_ _
(<type 'int'>,)
<code Python24>
>>>['a','b] [True]
'b'
>>>['a','b'] [False]
'a'
>>>['a','b']['some_string' == r'some_string']
'b'
>>>['a','b']['some_string' == r'somestring']
'a'

<code>
--
rbh
Jul 5 '07 #2
Hi Kelvie and RBH,

Thanks for your quick reply. That was very much helpful indeed.

regards,
kath.
Jul 5 '07 #3

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

Similar topics

17
4655
by: John Hunter | last post by:
I have a largish data set (1000 observations x 100 floating point variables), and some of the of the data are missing. I want to try a variety of clustering, neural network, etc, algorithms on the data, and to keep life simple I want to reduce the dimensions of the matrix so that I have no missing values, since not all the algorithms are...
46
4178
by: Scott Chapman | last post by:
There seems to be an inconsistency here: Python 2.3.2 (#1, Oct 3 2003, 19:04:58) on linux2 >>> 1 == True True >>> 3 == True False >>> if 1: print "true" ....
17
3367
by: Gabriel Mejía | last post by:
Services or applications using ActiveX Data Objects (ADO) 2.0 or greater may intermittently return empty recordsets on queries that should be returning valid results. At the time the problem occurs, the same queries successfully return the expected data when run from non-ADO sources, such as from ISQL in Microsoft SQL Server. This problem...
1
8359
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What I want to do is to allow the user to click on the row that corresponds to the correct address, and have the code behind populate the form's...
5
1956
by: Scott Shuster | last post by:
Hi, I'm having some strange problems in VS employing a DataReader. Here's a small snippet of the code: .... objDR = objCMD.ExecuteReader() If objDR.Read() Then (true stuff) Else
43
2865
by: sinister | last post by:
Is MS Access a true RDBMS?
19
5024
by: MDC | last post by:
Why does this return true: IsDate("ISometimesHateProgrammingMarch2005") Is there another way to verify that this is not a date?? Thanks in advance! MDC
90
3368
by: John Salerno | last post by:
I'm a little confused. Why doesn't s evaluate to True in the first part, but it does in the second? Is the first statement something different? False print 'hi' hi Thanks.
40
2698
by: nufuhsus | last post by:
Hello all, First let me appologise if this has been answered but I could not find an acurate answer to this interesting problem. If the following is true: C:\Python25\rg.py>python Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) on win32 Type "help", "copyright", "credits" or "license" for more
0
777
by: rempit | last post by:
Is it true???Help me please.. I want to search data from Database..And..The result is view in new "DIV".. <%@ Page Language="vb" AutoEventWireup="false" Codebehind="new.aspx.vb" Inherits="Testing._new" %> <% Dim objDbConn, strConn, rsSearchResults, strSQL, I If Request.QueryString("action") <> "" Then
0
7518
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, 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...
0
7444
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...
0
7711
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, 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. ...
0
7805
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 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...
1
5367
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3478
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1932
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
1
1054
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
755
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.