Sublime Forum

Help with syntax highlighting

#1

So I’m a freshman in college taking my first cs course ,and I’ve been using sublime text, but I’ve recently ran into an issue with the syntax highlighting. My professor insists that when we define functions we should also define the type of the parameter and the type of the result like this. Eg. def double(n: int) -> int: return n * 2. Well the arrow seems to be messing about the syntax highlighting and I was wondering if there’s any fix for this. The language is python. Thanks!

0 Likes

#2

“def double(n: int) -> int: return n * 2” – This is not Python syntax!
I think, the “->” should represent an indent. But “n: int” or “int: return” is wrong. Python never uses keywords for types in declarations.
“def” is the keyword do define functions and methods. Variables will not seperately declared and they have no permanent type:

[code]
d = {} # type is now dict

d = 5 # type is now int[/code]
If you like this, you can add as comment the type you want to use.

The Python syntax for your example above is:

def double(n) return n * 2

0 Likes