“Comment écrire un code python correct” Réponses codées

Comment écrire un code python correct

d = {'hello': 'world'}

print(d.get('hello', 'default_value')) # prints 'world'
print(d.get('thingy', 'default_value')) # prints 'default_value'

# Or:
if 'hello' in d:
    print(d['hello'])
Curious Chipmunk

Comment écrire un code python correct

my_very_big_string = (
    "For a long time I used to go to bed early. Sometimes, "
    "when I had put out my candle, my eyes would close so quickly "
    "that I had not even time to say “I’m going to sleep.”"
)

from some.deep.module.inside.a.module import (
    a_nice_function, another_nice_function, yet_another_nice_function)
Curious Chipmunk

Comment écrire un code python correct

$ pycodestyle optparse.py
optparse.py:69:11: E401 multiple imports on one line
optparse.py:77:1: E302 expected 2 blank lines, found 1
optparse.py:88:5: E301 expected 1 blank line, found 0
optparse.py:222:34: W602 deprecated form of raising exception
optparse.py:347:31: E211 whitespace before '('
optparse.py:357:17: E201 whitespace after '{'
optparse.py:472:29: E221 multiple spaces before operator
optparse.py:544:21: W601 .has_key() is deprecated, use 'in'
Curious Chipmunk

Comment écrire un code python correct

a = [3, 4, 5]
b = a

# assign the variable "a" to a new list without changing "b"
a = [i + 3 for i in a]
Curious Chipmunk

Comment écrire un code python correct

a = [3, 4, 5]
a = [i + 3]
Obnoxious Osprey

Comment écrire un code python correct

four_lists = [[] for __ in range(4)]
Curious Chipmunk

Réponses similaires à “Comment écrire un code python correct”

Questions similaires à “Comment écrire un code python correct”

Plus de réponses similaires à “Comment écrire un code python correct” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code