Questions tagged [parentheses]

The symbols "(" and ")", commonly used in programming languages. Please use this tag only if the specific usage of these symbols is a relevant part of the question.

The parentheses "(" and ")" are special cases of brackets, along with square brackets ("[" and "]") and curly brackets (or braces) ("{", "}").

Parentheses (singular parenthesis) have many uses in most programming languages, such as:

  • indicate the arguments of a function call;
  • specify the order of evaluation/execution of expressions;
  • create lists/arrays/vectors.
1024 questions
9
votes
6 answers

How to remove all text between the outer parentheses in a string?

When I have a string like this: s1 = 'stuff(remove_me)' I can easily remove the parentheses and the text within using # returns 'stuff' res1 = re.sub(r'\([^)]*\)', '', s1) as explained here. But I sometimes encounter nested expressions like…
Cleb
  • 25,102
  • 20
  • 116
  • 151
9
votes
1 answer

Is there a way to color code matching parentheses in R studio?

Everything I am finding online discusses highlighting matching parentheses, but I'm wondering if there is a specific editor theme or perhaps something else I could use for R studio that will color code matching parentheses within nested parentheses.…
ENIAC-6
  • 313
  • 8
  • 18
9
votes
4 answers

C# remove parenthesis from string

This seems to be a common question for C# users and after research and multiple attempts I cant for the life of me remove a pair of parenthesis from a string. The string I am having a problem with is Service (additional). After doing my research I…
user2405778
  • 467
  • 6
  • 16
  • 29
9
votes
1 answer

sqlalchemy how to using AND in OR operation?

i need to do this query: SELECT * FROM tbl_member WHERE (member_type==1 AND member_status==1) OR (member_type==2 and member_status==2) i've tried: q=session.query(tbl_member) \ …
nick.xu
  • 103
  • 1
  • 1
  • 4
9
votes
2 answers

Parentheses at the end of a C++11 lambda expression

I am confused with some of the examples that I have come across with C++11 lambdas. For eg: #include #include using namespace std; int main() { cout << []()->string{return "Hello World 1!";}() << endl; …
Quiescent
  • 1,088
  • 7
  • 18
9
votes
1 answer

Parentheses in block variables

Given a = [[:a, :b, :c]] 1) I understand this a.each{|(x, y), z| p z} # => :b that there are two variables (x, y) and z, so the third element :c is thrown away, and z matches :b. And I understand this a.each{|(x, y), z| p y} # => nil that (x, y)…
sawa
  • 165,429
  • 45
  • 277
  • 381
9
votes
2 answers

How do I infer the usage of parentheses when translating an expression tree?

I am working on translating an expression tree to a format that resembles infix notation; I am not evaluating the tree or executing its operations. The tree contains both logical and relational operations, and I would like to emit parentheses in an…
Steve Guidi
  • 19,700
  • 9
  • 74
  • 90
8
votes
15 answers

languages with functions that do not need parentheses?

IIRC, vb6 allowed function calls with no (). IIRC, it was allowed whenever the func didn't have a return value, and you could always use func(same, params, here). What other languages allow this? What do you think func with no parentheses should…
user34537
8
votes
2 answers

PHP and NLP: Nested parenthesis (parser output) to array?

Would like to turn text with nested parenthesis to a nested array. Here is an example output from an NLP parser: (TOP (S (NP (PRP I)) (VP (VBP love) (NP (NP (DT a) (JJ big) (NN bed)) (PP (IN of) (NP (NNS roses))))) (. .))) (orig: I love a big bed…
giorgio79
  • 3,787
  • 9
  • 53
  • 85
8
votes
1 answer

Braces: [Brackets], (Parentheses) & {Curlies} in Ruby & Rails

So the loose tolerance of Ruby to use braces sometimes and not REQUIRE them has led to alot of confusion for me as I'm trying to learn Rails and when/where to use each and why? Sometimes parameters or values are passed as (@user, @comment) and other…
Meltemi
  • 37,979
  • 50
  • 195
  • 293
8
votes
3 answers

What are the parentheses for at the end of Python method names?

I'm a beginner to Python and programming in general. Right now, I'm having trouble understanding the function of empty parentheses at the end of method names, built-in or user-created. For example, if I write: print "This string will now be…
David Kennell
  • 1,147
  • 2
  • 11
  • 22
8
votes
6 answers

Find the minimum number of edits to balance parentheses?

I was very confused about this question. I know about finding the edit distance between 2 strings using recursion and dynamic programming as an improvement, however am confused about how to go with this one. Not sure if my thinking is correct. But…
user3626602
  • 143
  • 2
  • 2
  • 8
8
votes
3 answers

What is the difference between echo with braces and without braces, and why do both methods exist?

I think most of us that program in php learned to echo "string";. While common, I am wondering why we use this so different then any other function. So why do we do: echo "Some String"; Instead of echo("Some String"); And why do both exist and…
Damien Overeem
  • 4,487
  • 4
  • 36
  • 55
8
votes
4 answers

Missing parentheses with Regex

Am I correct in thinking that Regex can't be used to detect missing parentheses (because there is no way of counting pairs)? Using JavaScript I've about a thousand strings which have been truncated and need to be edited by hand. I was hoping to be…
Ghoul Fool
  • 6,249
  • 10
  • 67
  • 125
8
votes
6 answers

Why an Integer within the parentheses of an ArrayList

Somewhere I saw a java.util.List defined as below. List myList = new ArrayList(0); Can anybody explain what the integer in parentheses does and how to use it? Thanks.
prageeth
  • 7,159
  • 7
  • 44
  • 72