Python Case Types and Naming Conventions
Skills:
AI Pair Programming80%
Key Takeaways
The video covers Python case types and naming conventions, following the official Python style guide PEP 8, to improve coding practices in Python.
Full Transcript
what is going on guys welcome back in today's video we're going to take a look at the different case types and programming and in particular we're going to take a look at the python naming conventions so which case types to use for which situations for variables for functions for classes and so on so let us get right into it it's not a game it's a [Music] red all right now this video is a little bit more casual because how you name your variables functions and classes doesn't have an influence on the functionality of your code however it makes your code more readable and more professional which is why you should stick to the nameing conventions and you should also know the names of the different case types so that you can communicate some styling decisions some style guides whenever that's necessary so let's get right into it we have a couple of different case types and I'm not sure that the list I'm going to show you here is complete but those are the most common ones and those are the ones that I found uh maybe there are some exotic case types that are not listed here and then can leave them in the comment section down below now one of the most commonly used case types even though not in Python is the camel case so camel case basically means that you start with a lowercase character so we're going to always use the name here my variable name and we're going to uh write it in the different cases so in this case what we would do is we would start with a lowercase M and we would continue with an uppercase character for every new word so my variable name like this that would be the camel case and this is what we use in a lot of programming languages to uh name functions and variables so for example in Java that's the case if you created a variable in Java what you do is you say in my variable name and then equals 10 or something uh and then of course a semicolon in Java but um this is not something that we use in Python so it's a commonly used case but it's not used in Python really actually I don't know any use case in Python so I think this is completely unless the module itself I think there's some um modules that have for example I think open CV might be one if we import CV2 maybe CV2 dot yeah destroy all windows so this is um used by some packages but in general in Python that's not something that is um defined in a naming convention but probably it's used because uh CB2 is not implemented in Python uh originally um another case we have is the snake case and as the name already says this is uh a snake python is also a snake it is used in Python for a lot of things for variables for function names and this would be just using underscores to separate the words and other than that keeping everything in lowercase so my variable name would be that uh or also mycore function name would also be a possibility so when we say something like my variable equals 10 or Dev my function we use the snake case and this is also the convention in Python by the way you can look at the conventions by visiting the following link and if I'm not uh if I don't forget it you will find the link in the description down below and this is the ps. python.org SLP I don't know why the copy pasting happened like this here but that is the link uh ps. python.org p- 00008 this is where you can read about all the naming conventions all the the uh conventions for writing professional python code and I have a video on a complete uh summary of that so you can watch it as well if you want to but today we're going to focus more on the cases here so that is the most commonly used case in Python for functions for variable names um but we also have different uh cases in Python that are used and one such case is the so-called Pascal case which probably the name probably comes from the fact that it was um used in Pascal um and this is used this is also called sometimes the capital camel case because it is like the camel case but we start with an uppercase character so it would be my variable name or actually what we most of the time use this for is for classes and this is the case for Java but also for python so when we define a class in Python we start with a uppercase character and we don't use underscores but we just start uh we just add with we just add additional uppercase characters for the start of every new word so my class name would be the convention here uh and this is called the Pascal case or the capital camel case so we can maybe add this here as well Capital cam case actually written in that case so that is what we use for classes then we also have the keup case I hope this is pronounced correctly I'm sorry if not and the basic idea here is it's like the snake case but instead of using underscores we use dashes or hyphens so we say my Dash barable Dash name and this is often times used for installing packages now I don't know to be honest if that's a convention because I don't think that you have to do it but this is what you usually do when you install uh packages with uh with Pip you type pip install and then for example open cv- python or even though the module when you import it is called pandas data reader so you can import pandas data reader uh like that in snake case the installation is actually pip install pandas Das data reader so that would be this case that we're talking about here and this case has a lot of different names uh some of them are lisp case or caterpillar case um and a bunch of more that I don't want to list now all of them here but but this is a quite common case and in Python it's mostly you will mostly encounter it when installing packages often times when you have also s kit learned for for example even though you import SK learn right so for packages this is uh quite common then we also have the upper snake case and the upper snake case is essentially um just using capital letters and then the snake case so something like my variable name like this uh but usually it's not used for variables but for constants so when you have something like my constant you would do it like this you would Define at the top of your script somewhere my constant equals 10 my constant 2al 20 or something whatever uh and this is the convention to use uppercase characters and of course if it's only one word with all of those by the way if it's only one word so if you have something like um I don't know let's call this neural if that is the variable name in camel case it's neural in snake case it's neural in uh Pascal case it would be with a capital N uh in keup case it would be again lowercase and in uppercase it would be just complete uh uppercase text like this so if you don't have to use these separators if you don't have to start with a new capital letter if you don't have to use underscores or dashes uh or hyphens uh whatever you don't have to do it you just write one word without these separators uh what else do we have we have the flat case uh which is essentially just uh and I think you also have the upper flat case even though I didn't list it here in my PR prepared note here um but essentially this is just no separators whatsoever it would be my variable name leading of course to not so readable names right and especially if you have something long like often times when you when you define test functions in in programming languages you have to describe what the test function is doing so you would do something like test uh connecting to Resource with valid data should return 200 or something that would be a typical name for a test function and if you use a flat case of course it looks like this and it's not very readable and I don't recommend doing it and I don't think that anyone is doing that but um yeah probably this is something that you might want to use if you if that's part of the convention of the programming language and you have some simple variable names that would be a possible use case and then finally I want to show you here the cobal case or cobal case I'm not sure how this is pronounced uh it's basically an uppercase uh it's like the upper snake case but instead of using um underscores we use dashes or hyphens so the caterpillar case or List case or whatever uh but in uppercase characters so it would be something like my Das variable Dash name like this so those are the basic cases again if you know some additional ones that are maybe quite exotic let me know in the comment section down below with some examples uh but what I want to do now is I want to go through some very basic python uh code it's not really something that does anything but I want to show you uh where you would do what in Python so first of all for installing packages so pip install in this case would be opencv-python but then the import would be import CV2 and if you had to do something um with multiple words as I said you would do something like pip install pandas data reader uh pandas Dash data reader sorry and we would import pandascore data reader so those are the conventions this is how you name packages with this list case here um and this is how you import them or how you name the packages when you have to import them how you name the modules you use snake case um and then we Define some constants for example like screen width this is done in the upper snake case so for example TH or what was it 1,920 screen height is equal to 1,80 um and then if we define a class for example my visualization for this we use the Pascal case so uppercase character at the start and then an uppercase character for each new word then we have the init function here which is special it's a double under function so this is not necessarily A convention this is just the way this function uh is named uh and then we could do here something like maybe um we could say width height so the parameters are in snake case so if we had something like uh screen height we would do it like this um but let's just go with height here and then we would do self. width equals width self do height come on height equals height and then we would do something like do visualization then we do some code here it doesn't really matter but if we have a variable here for example some calculated value equals self. width or self. height doesn't really matter times 2 plus I don't know self dot width divided by two just some random calculation here and then you can do some stuff here so do stuff for the functionality then if we create an instance of that class the class is named with Pascal case the instance is named again with snake case so we do something like my uncore visualization is equal to my visualization like this then my visualization do visualization with the constants from above screen width screen height right so those are the conventions just remember packages in um this case here I don't want to pronounce it again mispronounce it again catapillar case um in yeah that that's that you have the snake case essentially for module names for function names for variable names for everything for instance names whatever which is again a variable um and you have the Pascal case for the classes and you have of course the upper snake case or any upper case for that matter for constants so that's it for today's video I hope you enjoyed it and hope you learned something if so let me know by hitting the like button and leaving a comment in the comment section down below and of course don't forget to subscribe to this Channel and hit the notification Bell to not miss a single future video for free other than that thank you much for watching see you on the next video and bye [Music]
Original Description
In this video, we learn about the different case types there are in programming and when to use what in Python, according to the naming conventions.
Style Guide: https://peps.python.org/pep-0008/
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
🐍 The Python Bible Book: https://www.neuralnine.com/books/
💻 The Algorithm Bible Book: https://www.neuralnine.com/books/
👕 Programming Merch: https://www.neuralnine.com/shop
🌐 Social Media & Contact 🌐
📱 Website: https://www.neuralnine.com/
📷 Instagram: https://www.instagram.com/neuralnine
🐦 Twitter: https://twitter.com/neuralnine
🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/
📁 GitHub: https://github.com/NeuralNine
🎙 Discord: https://discord.gg/JU4xr8U3dm
🎵 Outro Music From: https://www.bensound.com/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from NeuralNine · NeuralNine · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
Python Beginner Tutorial #5 - Loops
NeuralNine
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
Python Beginner Tutorial #7 - Functions
NeuralNine
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
Python Beginner Tutorial #9 - File Operations
NeuralNine
Python Beginner Tutorial #10 - String Functions
NeuralNine
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
Python Intermediate Tutorial #6 - Queues
NeuralNine
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
Python Intermediate Tutorial #9 - Recursion
NeuralNine
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
Python Intermediate Tutorial #11 - Logging
NeuralNine
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
Python Machine Learning #4 - Support Vector Machines
NeuralNine
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
Making Text Images Readable Again with Python and OpenCV
NeuralNine
Neural Networks Simply Explained (Theory)
NeuralNine
Motion Filtering with OpenCV in Python
NeuralNine
Top 5 Programming Languages To Learn in 2020
NeuralNine
Simple TCP Chat Room in Python
NeuralNine
Image Classification with Neural Networks in Python
NeuralNine
Edge Detection with OpenCV in Python
NeuralNine
S&P 500 Web Scraping with Python
NeuralNine
Simple Sentiment Text Analysis in Python
NeuralNine
Introduction - Algorithms & Data Structures #1
NeuralNine
More on: AI Pair Programming
View skill →Related Reads
📰
📰
📰
📰
Software Engineer Interview Process at AI Startups
Medium · AI
Software Engineer Interview Process at AI Startups
Medium · Machine Learning
Software Engineer Interview Process at AI Startups
Medium · Data Science
Building a Deepfake Detection System That Actually Explains Its Decisions
Medium · Machine Learning
🎓
Tutor Explanation
DeepCamp AI