Last active
December 25, 2019 22:19
-
-
Save EmmanuelKasper/095f4bf17bb10df47cd74ef09fb7b6b5 to your computer and use it in GitHub Desktop.
Different line joinings in pyton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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