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

what does ` ` do in ' '.join([`x * x` for x in range(1, 6)])?

' '.join([`x * x` for x in range(1, 6)])

exactly what does this symbol do and what does it stand for?
Sep 27 '08 #1
7 1825
process <ci**********@gmail.comwrites:
' '.join([`x * x` for x in range(1, 6)])

exactly what does this symbol do and what does it stand for?
It's an obsolete, deprecated syntactic sugar for (what is now
implemented as) the built-in 'repr' function.

Instead, write the above as:

' '.join([repr(x * x) for x in range(1, 6)])

--
\ “Killing the creator was the traditional method of patent |
`\ protection” —Terry Pratchett, _Small Gods_ |
_o__) |
Ben Finney
Sep 27 '08 #2
On Sep 27, 12:39*pm, process <circularf...@gmail.comwrote:
' '.join([`x * x` for x in range(1, 6)])

exactly what does this symbol do and what does it stand for?
`<object>` is the same as repr(<object>). I'm pretty sure the backtick
operator has been removed from 3.0.

In the context of the code sample you posted, it appears to be used to
convert the result of x*x into a string for the join method, but I
personally think it's a misuse of repr() and think a call to str()
would be more appropriate:
>>' '.join((str(x * x) for x in range(1,6)))
'1 4 9 16 25'

Sep 27 '08 #3
r0g
process wrote:
' '.join([`x * x` for x in range(1, 6)])

exactly what does this symbol do and what does it stand for?

Which symbol, the '*' ???

Are you kidding?
Sep 27 '08 #4
r0g
process wrote:
' '.join([`x * x` for x in range(1, 6)])

exactly what does this symbol do and what does it stand for?
Ah, just spotted the backticks - they just return whatever's inside them
as a string.
Sep 27 '08 #5
On Sep 27, 3:58*pm, r0g <aioe....@technicalbloke.comwrote:
Ah, just spotted the backticks - they just return whatever's inside them
as a string.
No, they return the repr() of the object inside. The output of
__repr__ -has- to be a string, but typecasting into string isn't the
intention of repr() (or the ` operator).
Sep 27 '08 #6
In article
<40**********************************@w39g2000prb. googlegroups.com>,
alex23 <wu*****@gmail.comwrote:
' '.join((str(x * x) for x in range(1,6)))
Aren't the outer set of parens redundant? This works just as well:

' '.join(str(x * x) for x in range(1,6))
Sep 27 '08 #7
On Sep 27, 4:16*am, Ben Finney <bignose+hates-s...@benfinney.id.au>
wrote:
process <circularf...@gmail.comwrites:
' '.join([`x * x` for x in range(1, 6)])
exactly what does this symbol do and what does it stand for?

It's an obsolete, deprecated syntactic sugar for (what is now
implemented as) the built-in 'repr' function.

Instead, write the above as:

* * ' '.join([repr(x * x) for x in range(1, 6)])
I'd classify it as one of Guido's mistakes! :-)
Sep 27 '08 #8

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

Similar topics

3
by: Derek Fountain | last post by:
The documentation says session_destroy() "destroys all of the data associated with the current session". Um, like what? The docs further say that you should remove all information in the _SESSION...
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...
2
by: Steve Richter | last post by:
What does the "." mean in the following sql script stmts? use GO if exists (select * from dbo.sysobjects where id = object_id(N'.') and OBJECTPROPERTY(id,N'IsUserTable') = 1) drop table ....
8
by: Kim Forbes | last post by:
I am learning Javascript; and most books only give you partial definitions for the functions they show you. Here is a line of code from a browser sniffing function: var isWin =...
58
by: Larry David | last post by:
Ok, first of all, let's get the obvious stuff out of the way. I'm an idiot. So please indulge me for a moment. Consider it an act of "community service".... What does "64bit" mean to your friendly...
2
by: Tom | last post by:
I'm getting this error when I try to pass a structure to a dll. An unhandled exception of type 'System.ArgumentException' occured in Test1.exe Additional Information: Type could not be marshaled...
0
arunmib
by: arunmib | last post by:
Hi all, I have doubt, as what does __declspec (dllimport) or __declspec(dllexport) does? If add these only the functions of a dll are exported or imported right? So what exactly does...
9
by: JoeC | last post by:
m_iWidth = (int)pBitmapInfo->bmiHeader.biWidth; m_iHeight = (int)pBitmapInfo->bmiHeader.biHeight; What does this mean? I have seen v=&var->member.thing; but what does it mean when you...
92
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
2
by: Lambda | last post by:
The code is simple: // Token.h #ifndef TOKEN_H #define TOKEN_H #include <vector> #include <string> class Token
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...

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.