0
What is the point of a : ?
If I do something like: for i in range (100): Why does the little : make or break the code?
2 Respostas
+ 3
Every language has their own rules of syntax.
The colon in Python introduce a block of code.
class C:
# class definition
def f():
# function definition
if 1==1:
# if block code
... and so on.
One could say, why not skip the colon? Isn't indentation enough?
Maybe it's just to make it feel more like regular human texr?
'Three factors are guiding us here:
* blabla
* more blabla
'
+ 3
The colon ":" in python is also used in slices like :
txt = 'abcd'
txt[1:]
# output: 'bcd'
txt[1:3]
# output: 'bc'