Python Forum
New to python, question regarding PEP8
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New to python, question regarding PEP8
#2
Formatting is okay.
It give warning because your dictionary values is a little long(uncommon) with split up text on new line.
Black is used much and have become more like standard way of formatting code in Python.
So eg Black will format it automatically like in code i show under.
definitions = {
    "For loops": "For loops allow you to run a block of code repeatedly, just like while loops. However, for loops run"
    "a block of code a set number of times.",
    "Functions": "A function is a block of code repeatedly, just like while loops. However, for loops run a block of"
    "code a set number of times",
    "If statements": "An if statement runs a block of code based on whether or not a condition is true.",
    "Loops": "Loops check a condition and then run a code block. The loop will continue to check and run until a "
    "specified condition is reached.",
    "Python": "Python is a programming language that's currently becoming more and more powerful with every new library"
    " added to its collection.",
}   
So a more common dict it will be format like this.
# Orginal
d = {"apple": "fruit", "ball": "object", "cricket": "sports", 'car': 'vehicles'}

# After Black
d = {
    "apple": "fruit",
    "ball": "object",
    "cricket": "sports",
    "car": "vehicles",
}
It's normal to have a formatter integrated in Editor,i have used Black for many years in VS Code.
For PyCharm look at Editor integration
Can also test online here Black Playground.
Reply


Messages In This Thread
RE: New to python, question regarding PEP8 - by snippsat - Apr-14-2022, 12:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Noob warning: trying to use pip to install pytest and pep8 in Command Prompt adifrank 4 5,617 Dec-20-2020, 04:23 AM
Last Post: adifrank
  Type hinting style and PEP8 hlovatt 2 2,992 May-07-2020, 08:12 PM
Last Post: hlovatt
  Visual Studio Code - PEP8 Lambda Issue Qui_Ten 1 2,823 Jan-28-2019, 08:17 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020