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?

30th Oct 2019, 4:56 AM
Theodore206
Theodore206 - avatar
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 '
30th Oct 2019, 8:47 AM
HonFu
HonFu - avatar
+ 3
The colon ":" in python is also used in slices like : txt = 'abcd' txt[1:] # output: 'bcd' txt[1:3] # output: 'bc'
30th Oct 2019, 10:57 AM
Lothar
Lothar - avatar