Skip to content

Instantly share code, notes, and snippets.

@EmmanuelKasper
Last active December 25, 2019 22:19
Show Gist options
  • Save EmmanuelKasper/095f4bf17bb10df47cd74ef09fb7b6b5 to your computer and use it in GitHub Desktop.
Save EmmanuelKasper/095f4bf17bb10df47cd74ef09fb7b6b5 to your computer and use it in GitHub Desktop.
Different line joinings in pyton
#!/usr/bin/python3
def output():
# explicit line joining with backslash (prefered for simple strings)
print("let's do some calculations \
of the body mass index")
# explicit line joining with operator # generally prefered, allows to keep indentation consistent
# PEP 8 recommends operator on the next line
print(f"weight: 75, size: 1.77 "
+ f"bmi: {bmi_calc(75,1.77)}")
# implicit line joining
# Expressions in parentheses, square brackets or curly braces
# can be split over more than one physical line without using backslashes
def bmi_calc(weight,
height):
return weight / height**2
output()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment