Python – Multi-line Statements


a = [1, 
     2, 
     3]

a = [1, # comment 
     2, # comment
     3] # comment

a = (1,
     2,
     3)

a = {1,
     2,
     3}

a = {'key1': 'value1',
     'key2': 'value2',
     'key3': 'value3'}

def my_func(a,
            b,
            c):
    print(a, b, c)

a = 10
b = 20
c = 30
if a > 5 \
    and b > 10 \
    and c > 20:
    print('OK')

a = "this is
a multi-line string"
print(a)
  File "<ipython-input-48-bff902a77458>", line 1
    a = "this is
                ^
SyntaxError: EOL while scanning string literal

a = "this is \
a multi-line string"
print(a)
this is a multi-line string

a = "this is \
     a multi-line string"
print(a)
this is      a multi-line string

a = '''this is
a multi-line string'''
print(a)
this is
a multi-line string

a = '''this is
       a multi-line string'''
print(a)
this is
       a multi-line string

a = """this is
       a multi-line string"""
print(a)
this is
       a multi-line string

a = '''this is \
a multi-line string'''
print(a)
this is a multi-line string

def my_func():
    a = '''a multi-line string
    that is actually indented in the second line'''
    return a

print(my_func())
a multi-line string
    that is actually indented in the second line

def my_func():
    a = '''a multi-line string
that is actually indented in the second line'''
    return a

print(my_func())
a multi-line string
that is actually indented in the second line

Fermer le menu