Skip to main content
42 votes

Does Python's semicolon statement ending feature have any unique use?

When executing a python snippet via python -c from bash, I find using semicolons more convenient than having to inject newlines. (In particular when the snippet has ...
abel1502's user avatar
  • 2,537
24 votes
Accepted

In Python, why isn't it a syntax error when a list of strings is defined without comma separators?

The reason the first example does not error is because Python will automatically concatenate adjacent string literals. This happens inside and outside of lists. As mentioned in the Python ...
lyxal's user avatar
  • 1,825
12 votes

Does Python's semicolon statement ending feature have any unique use?

In Python specifically, the main use case is to eliminate newlines in a bit of code you are running. The common case for this is using the -c argument for the ...
Austin Hemmelgarn's user avatar
10 votes

Why does Python ignore type hints?

Python's typing model is intended for outside checkers to check python code. Pretty much any expression can go in a type hint: x: print("hi") = 1 print(x) ...
blueberry's user avatar
  • 2,587
10 votes

What benefits does Python gain from not having constants?

I'm not sure that Python specifically doesn't have them because of any concrete advantages to not having them. That is, there may be such advantages (one is discussed in mousetail's answer), but I don'...
kaya3's user avatar
  • 20k
9 votes

Does Python's semicolon statement ending feature have any unique use?

Similar to what abel1502 said about executing code from bash, I find myself using semicolons when using pdb and trying to do anything involving multiple lines. It's ...
fyrepenguin's user avatar
9 votes

Why does Python not allow us to call functions like other languages do?

This pattern is not as common as you think It looks like you're referencing MATLAB there. MATLAB is the only language I know that forces a file to be in one-to-one correspondence with the language's ...
Silvio Mayolo's user avatar
9 votes

What benefits does Python gain from not having constants?

Monkey Patching A core feature of Python is that absolutely everything is accessible and modifiable. Even things like closure bound variables, which are still truly private even in JavaScript, are ...
mousetail's user avatar
  • 8,531
8 votes

How to transpile between languages with different scoping rules?

When TypeScript needs variable names to not conflict, it suffixes variables of otherwise identical names with _1, _2, etc. You ...
Bbrk24's user avatar
  • 9,117
7 votes
Accepted

Why does Python ignore type hints?

Type hinting is a relatively recent addition to Python, so older code, and still most code, doesn't use them at all. Annotated code still needs to work with that existing code, so Python is a gradual ...
Michael Homer's user avatar
  • 13.1k
6 votes

What are the advantages and disadvantages of package declarations?

Disadvantage: If you know where the source root is, this is a redundant information, while users will still have to fill it in every time they write a file. Moving a file from one package to another ...
ice1000's user avatar
  • 2,504
6 votes

In Julia, what is the benefit of requiring commas between elements when defining a vector for a dot product?

As hinted by the error message: Note the difference between 1d column vector [1,2,3] and 2d row vector [1 2 3]. The two literal syntaxes define different objects, ...
kouta-kun's user avatar
  • 1,469
5 votes
Accepted

What is the difference between JS's map and Python's dictionary?

Background: I was an implementer of Microsoft's JScript engine in the 1990s and for a time a member of the ECMAScript technical committee. And if so, why they aren't called the same? Given that JS is ...
Eric Lippert's user avatar
  • 3,519
5 votes
Accepted

Is it correct that Python does not encourage us to read objects's content?

TL;DR Javascript was not at first intended to be a general purpose programming language, Python was. Longer Answer Javascript was developed in 1995 to add small amounts of behavior to web pages that ...
Jared Smith's user avatar
5 votes

How to transpile between languages with different scoping rules?

The scope of a variable can be expanded by moving its declaration further out; to translate between block-scoped and function-scoped variables, you need to make sure the declaration is at the top of ...
kaya3's user avatar
  • 20k
5 votes

Why does Python ignore type hints?

Python is a dynamically typed language, and neither its developers nor most of its users want it to become a statically typed language instead. It's true that there are possible positions between &...
kaya3's user avatar
  • 20k
4 votes
Accepted

Are you allowed to use almost identical language to another language?

You can make any language you want. Many languages take strong inspiration from one or more others and significantly overlap (consider C→C++). It's also very common for operations like ...
Michael Homer's user avatar
  • 13.1k
4 votes

Why does Python ignore type hints?

In both the design of the Python language, and the design of the CPython interpreter (effectively the default implementation of Python, but there are others), performance is not a major objective. ...
Gilles 'SO- stop being evil''s user avatar
3 votes
Accepted

How is a python namespace implemented in terms of memory under Cpython implementation?

Python allows you to inspect the global scope with the globals() function. Let's try it out: ...
Michael Homer's user avatar
  • 13.1k
3 votes

How JIT in R compares to JIT in Julia and JIT in Python?

One difference is whether the code is compiled to bytecode or native code. GNU R evaluates code by converting it to bytecode and then interpreting the bytecode (the bytecode interpreter is called a ...
tarzh's user avatar
  • 4,049
2 votes
Accepted

Does CPython compile the entire code or one piece at a time?

Python will always compiles to bytecode before executing. You can view the bytecode of some function using the dis standard library method: ...
mousetail's user avatar
  • 8,531
2 votes

Why does Python not allow us to call functions like other languages do?

There are a few reasons: As you said, so no two namespaces have the same name. Readability and clarity. The module.function() syntax provides clear information ...
Starship's user avatar
  • 1,336
2 votes

What is the difference between JS's map and Python's dictionary?

Python dicts and JavaScript Maps are broadly equivalent in role, though the APIs and precise capabilities do differ. The semantics of iteration, key identity, and various additional methods differ, ...
Michael Homer's user avatar
  • 13.1k
2 votes

How JIT in R compares to JIT in Julia and JIT in Python?

Overview Your question implicitly covers three different comparisons: Different execution models used in implementations of a language. For instance, the same Python code can be executed using either ...
IMSoP's user avatar
  • 2,458
1 vote

How JIT in R compares to JIT in Julia and JIT in Python?

Are there characteristics of the language that make the compiler's job harder or less efficient in some language compared to others? This is the main difference. For lots of details, I recommend ...
Oscar Smith's user avatar
1 vote
Accepted

Why does python allow single-line compound statements?

Compound statements are produced by the parser as part of the "suite" production, which groups up nested scopes into a syntax tree. One-line compound statements are allowed by not requiring ...
Corbin's user avatar
  • 851
1 vote

Why does python allow single-line compound statements?

Mostly to make it easy to write one-liners like python -c "for i in range(0,10): print(i)"
Chris Dodd's user avatar
1 vote

Does Python's semicolon statement ending feature have any unique use?

I used this feature when embedding Python code in an editor for a Jupyter-notebook-like experience. The code is a recipe for baking bread. It is also a template, meant to be loaded into the current ...
piojo's user avatar
  • 111

Only top scored, non community-wiki answers of a minimum length are eligible