Write Python Code Properly!

preview_player
Показать описание
Welcome back to another video! In this video, I am going to be showing you the proper way to write Python code. What I mean is that I will be going over the proper python conventions and the most important parts of the python style guide known as PEP8. There is a lot in PEP8 but I'll only go over the most common mistakes made.

📄 Resources 📄

⭐️ Timestamps ⭐️
00:00 | Write Proper Code!
02:27 | PEP8 Guideline
03:00 | Installing An Auto Formatter
05:29 | General PEP8 Guidelines
07:01 | Naming Conventions
10:55 | Method Parameter Naming
12:01 | Function And Class Spacing
13:33 | Imports
15:42 | Single Or Double Quotes
17:16 | Whitespaces
21:02 | In-Line Comments
22:12 | is None or == None
24:05 | Try and Except
24:46 | String Prefix and Suffix

◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
💰 Courses & Merch 💰

🔗 Social Medias 🔗

🎬 My YouTube Gear 🎬

💸 Donations 💸
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️

⭐️ Tags ⭐️
-Tech With Tim
- Python
- Code
- Write Code Properly
- Pep8
- HarperD8

⭐️ Hashtags ⭐️
#TechWithTim #Python
Рекомендации по теме
Комментарии
Автор

Cases:
snake_case
lowerCamelCase
UpperCamelCase / PascalCase
SCREAMING_SNAKE_CASE

haibai
Автор

For such a versatile, and useful language, many of Python's conventions are absolutely assinine.

bassam.
Автор

Random things: order of imports is recommended to be future imports, builtin packages, 3rd party modules, project specific imports, each separated with a newline.
When you have a keyword argument with a typehint, you add the extra spaces: def foo(str: arugment = “hi”):

huantian
Автор

I love the way that snake case looks in PEP-8. At first I was not excited about having to reach my fingers to do the awkward _ characters, but really, I only need to type those when I first declare the variable. Every other time I use that variable, I can just use my editor's autocomplete and just skip all the underscore characters and then just hit tab to accept the autocomplete.

exstasis
Автор

Tim I'm beginner at python and overall new to programming your videos are helping me a lot. I'm really interested in data analysis can you please make some videos on this topic

tahirahmed
Автор

I was actually researching on this thank you Tim

tadiwashangwa
Автор

You are right now my most favourite person on this planet...❤️ Thanks a ton for all the learning videos

ankitaburman
Автор

If you use if foo[3:] == "bar" and you subsequently change "bar" to "barf", your code is broken unless you also edit the slice size. This is brittle. That's why Guido recommends endswith and startswith.

ncmathsadist
Автор

Also could you cover what to do for parameter and return type and the spacing for it? For example def function(a:int, b:list) -> list

roydadancegod
Автор

Excellent, to-the-point summary of PEP8 convention. Thank you.

zulucharlie
Автор

Hi Tim, i'm very new to tech and a career changer, i just want to say that the content here is one of the best explanations i've found scouring the interwebs!

Cpt_Diabetes
Автор

Unconsciously I follow all pep8 style guide you have discussed in this video 😄

sumitpatidar
Автор

i didn't know about the startswith thing either, good to know. i've seen it around used a lot. question though, for function names that are multiple words, do these act similarly to variable names as in they are snake case as well, or is there some other way of denoting functions as opposed to variables? also, do we treat lambda functions any differently in this regard if they are stored in a variable?

TheFootballPlaya
Автор

this is awesome and explained well why these rules are used

zachfenton
Автор

Camel case: aka how you spot people who started in other programming languages and have a hard time breaking the habit in Python 😂

Markyroson
Автор

What screen recording + editing software do you use? Your code is presented very aesthetically and in an easy to read/comprehend way!

save-scum
Автор

Thank you for the video. I am grateful for your time and contribution. Kind regards, Akira.

akira_asahi
Автор

Love your vids! Could you do any about when you would use classes because I do get confused slightly.. maybe through doing a project - that would be ace!

AI-tgby
Автор

I swear every time I look something up, you release a new video on the subject lol
Thanks!

Landon_Hughes
Автор

Irony: in an article title "write proper python code" using "from os import path" as an example when Pathlib is by far the preferred solution for handling file paths

BartWillems