I have not understood why they write round(x[,n])
in syntax, but in codes they write round(10.6987,12)
without square brackets before comma i.e, round(10.6987[,12])
Asked
Active
Viewed 261 times
1

smeso
- 4,165
- 18
- 27

user2713461
- 387
- 2
- 5
- 16
2 Answers
5
The square brackets aren't intended to by typed into your code. They just indicate that n
is an optional parameter.
This style is recommended in the Documenting Python guide:
function
Describes a module-level function. The signature should include the parameters, enclosing optional parameters in brackets. Default values can be given if it enhances clarity. For example:
-
In python, is square brackets usage same as this normal usage , like
. – user2713461 Dec 23 '13 at 17:47 -
Yes, I believe some other languages will use `<` and `>` in a similar way. – Kevin Dec 23 '13 at 17:56
-
1@user2713461 In Python *documentation*, yes. But square brackets to denote optional things in general weren't invented by the Python folks, it's a widely used convention, for example in man pages (`cat [OPTION] [FILE]...`). – Dec 23 '13 at 17:57
-
1In fact the use of brackets for optionals predates the use for indexes. – f p Dec 23 '13 at 18:05