Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it true that I can't use curly braces in Python?

Tags:

python

I was reading that Python does all it's "code blocks" by indentation, rather than with curly braces. Is that right? So functions, if's and stuff like that all appear without surrounding their block with curly braces?

like image 559
openfrog Avatar asked Dec 20 '09 15:12

openfrog


People also ask

Are curly brackets allowed in Python?

Easily my favorite advanced feature in Python, rather than relying on whitespace to denote scopes (boring) — we can use curly braces!

Why does Python not use curly braces?

Those that get used to the Python way of doing things tend to start seeing curly braces as unnecessary line noise that clutters code. On the other hand, 'the whitespace thing' is possibly the single biggest reason why some developers refuse to even try Python.

What does {} brackets mean in Python?

[] brackets are used for lists. List contents can be changed, unlike tuple content. {} are used to define a dictionary in a "list" called a literal.

How do you write curly braces in Python?

Anything that is not contained in braces is considered literal text, which is copied unchanged to the output. If you need to include a brace character in the literal text, it can be escaped by doubling: {{ and }} . So if you want to print "{42}", you'd use "{{{0}}}". format(42) !


1 Answers

You can try to add support for braces using a future import statement, but it's not yet supported, so you'll get a syntax error:

>>> from __future__ import braces   File "<stdin>", line 1 SyntaxError: not a chance 
like image 173
Adam Rosenfield Avatar answered Sep 22 '22 01:09

Adam Rosenfield