Programming fundamentalsLesson 1 of 1 in the course Expressions

Python Whitespace, Multi-Line Strings, and Line Joining

5 flashcards · 5 quiz questions · 5 match pairs · 5 fill-in sentences · English

Lesson progress
0 / 5

Your progress is kept in this browser only.Sign up to save it

Summary

Good spacing makes Python code easier to read and understand, even when spacing does not change how a program runs. This lesson introduces common whitespace conventions, including guidelines from PEP 8.

name = input("Enter someone's name: ") place = input("Enter a famous place: ")

name=input ("Enter someone's name: " ) place =input("Enter a famous place: ")

All flashcards

PEP 8
The official Python style guide, which recommends conventions for readable and consistent code.
Adjacent string literal concatenation
Python joins neighboring string literals into one string without requiring a + operator.
Implicit line joining
Python continues a statement across lines inside parentheses, brackets, or braces.
Explicit line joining
A backslash at the end of a physical line joins it to the next.
Spaces in split string literals
Include spaces in the literal pieces when they are needed in the resulting string.

Quiz questions

  1. What does PEP stand for in the name PEP 8?Answer: Python Enhancement Proposal.
  2. Which function call follows PEP 8's spacing convention for parentheses?Answer: print("Hello")
  3. What does Python do with adjacent string literals such as "Hello, " "Python!"?Answer: It combines them into one string without inserting a line break.
  4. Which grouping characters allow implicit line joining in Python?Answer: Parentheses, brackets, and braces.
  5. What line length does PEP 8 recommend staying below when practical?Answer: 80 characters.

Based on Introduction to Python Programming by Udayan Das, Aubrey Lawson, Chris Mayfield, Narges Norouzi (OpenStax), licensed CC BY 4.0. Adapted into a summary, flashcards and quizzes.

All Programming fundamentals lessons