Python summary: spacing

We are free by adding spaces and newlines in Python. Some examples:

>>> print("Hello") is print( "Hello")
var1 = int(input("How old? "))
var2 = int( input("How old? ") )
# A name
#A name
# In dictionaries:
>>> our_dictionary={"name" : "Enric Baltasar" ,"age":20}
>>> phone_directory = {'Jack': 608475436,
                       'Phillip': 986585552,
                       'Peter': 688732233}

Limits are specific rules, our style and recommendations. For example, identation must have the same quantity and character type(s) (either tabs or spaces).

>>> number = 9
>>> if number == 9:
...   print("First text")
...         print("Second text")
  File "", line 3
    print("Second text")
IndentationError: unexpected indent


A related trick is, for convenience, to use a backslash (\) for viewing in our code different lines, but by running they are the same ones (new physical line, however the same logical line):

>>> print("Now I can buying something green")
Now I am buying something green
>>> print("Now I am buying \
... something green")
Now I can buying something green

And we can use a several backslashes.

More information:


Be First to Comment

Deja un comentario