1

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])

smeso
  • 4,165
  • 18
  • 27
user2713461
  • 387
  • 2
  • 5
  • 16

2 Answers2

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:

Community
  • 1
  • 1
Kevin
  • 74,910
  • 12
  • 133
  • 166
  • 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
  • 1
    In fact the use of brackets for optionals predates the use for indexes. – f p Dec 23 '13 at 18:05
1

Square brackets are just a convention used to indicate optional arguments.

smeso
  • 4,165
  • 18
  • 27