Python 08 Programming Style and Comments
Skills:
AI Pair Programming70%
Key Takeaways
Covers Python programming style and comments
Full Transcript
hey what's going on guys rudn shell.com here today and we are looking at even more python this is in fact your eighth tutorial I'm thinking and man man eight tutorials would you look at that anyway let's get started I'm going to open up idle and you should too and today we are going to try and look at the theory of Python Programming now python is kind of designed to to Really enforce and encourage like white space and and clean programming simple the it should be simple it should be clear it's understandable like the the naming conf the way things are named like printing things obviously print does things input to get input things like that things things are named certain ways so they so they make sense and we do that on purpose in Python especially when you have uh lots of white space you it it encourages is indenting and making clear code that you can see it you can understand when you're reading you can understand things when you're reading it it comes across clearly to you and that sort of thing but sometimes it might be tough for the programmer to really understand what's happening if they don't fully understand the background or anything like that so what a programmer could do is leave themselves like little notes throughout the program and throughout the source code of what's going on now the way they do that is with something called comments and that's kind of what I want to talk about in this tutorial other than the idea of keeping things clean and keeping things orderly and tidy and very neat but with comments though they come in two different ways they're they have single line comments and multi-line comments so now a comment can appear anywhere on a line but anything that is after the symbol that represents that comment is considered part of the comment like if we had print I don't know Doug and we print out Doug anything after that if we had a little hashtag here the hashtag is what represents a single line comment we could just say this is what outputs dug the string Doug we should make it a little bit more uh a little bit more precise so now that that comment is completely disregarded it's completely ignored because the python interpreter doesn't have to look at it it's just it's just a note for the programmer but if we put that anywhere else like say we put that I don't know before the print command it's not going to run whatsoever because it's a comment let me uh let me try that again yeah see nothing nothing happens whatsoever and we can have we can comment out comment tags we could have as many hashtags as we wanted to and put them at completely arbitrarily different places but the left most common symbol is what's going to take priority there and this is kind of interesting now you can play with this a lot because there's another there's another sort of comment here we have multi-line comments which I'm going to show you in a in a new window because I think this is little good let me save this as a file. python I'll show you guys what I'm doing first of all it's yeah that's already there but I'll overwrite it I'm just going to type in my shebang line for good practice suppose I don't really have to but you know the more the merrier I guess I don't even know how that idiom goes in that context but hey okay let's look at here let's look at what we got here let's print out Doug again CU he's kind of a nice guy so print out Doug F5 good that works perfectly fine so if we print out Doug this let's get our single comment here this displays Doug and there's no change whatsoever but if we did one two three single quotes the these are multi-line comments anything we type in between these these lines here these single quotation marks is a comment it's a whole commment the ENT no no matter how big you want it to be anything we type in between these symbols is a multi-line comment let me just type that and get it out of the way so we could type in raw input we could actually have some code in here that we don't want to run see now it's not going to ask us for the that raw input but let's say we put one right here there you go we could run that but now I get an error there's this oh that's that's the indentation my bad do it again there's still an error because there's an error in the program error while scanning triple quoted string literal so that comment is still it's sort of just floating around in space so we have we got we might want to clear that up so we'll put in another ending comment there so there's a comment that has absolutely nothing in it but that could help us in the long run too because if we if we run this it's asking us for raw input but if we had something in here and let's say we didn't want that code we could just comment it out or comment pieces of this out you can make like as many nests of comments as you want and this works the same for single line comments but it it won't be as orderly I suppose but the idea is you have the you have the capability and you have access to being able to give yourself notes and a little bit of a little bit of an understanding of what it is that you're doing in case you ever forget like maybe you you have this this program maybe you have the source code that you've been working on for for quite a while and then you sort of leave it alone for a little bit you don't touch it for a week maybe maybe a month and you come back and now you have all this code except you don't remember exactly what it does sometimes you can't you can't understand all of it so having these comments and writing and being able to write out what you can do and what you have done is great and you have these little tips and tricks where you can have like three sets of multi-line comments and you can get rid of things quickly and on the fly now I've done that plenty of times if we check out some of my programs I'll uh I'll open up python oh caps lock is on that's weird dream oh yeah this one here nothing in here just a little bit of gtk um let's open up let's see new vocab anything in here yeah look at this commented out code just because I feel like I don't need to test that for a little bit and in case if I ever need to uh uncomment that it makes it easy for me to just uncomment the top one but then we have all this crap that's commented so what you should do is have a blank comment immediately after that so that does the exact same thing though but I think if we put a single line comment here that does what we need and then if we take this one out it it understands this bottom one as a multi-line comment but if we had the top one up here it understands that as a single line comment does that make sense it's kind of like quickly getting rid quickly toggling code on and off only by removing a single line rather than having having to have to worry about both of them so I'll save that but and see i' I've been making uh I've been writing some my own comments here and what I do when I have a code block or a piece of program a piece of a piece of the code that has to be indented or at least has a little bit more logic structure I will actually comment out a a little tab or at least a little identifier like a stop sign for me to know okay when this this logic flow ends and I'll be able to talk more about that when we're actually looking at more keywords and more structures and more loops and conditional statements and that sort of thing but for now I still want you to guys I still want you guys to know this is this is the way people write code in Python sometimes it all depends on what you feel like is a good thing to do you can have naming conventions you can have comments sputtered all throughout your program and you can even make yourself little stop signs for understanding the white space and the logic flow but hey it all depends on what you want to do and that's a little bit of the fun of programming you have choice you have you have control you have manipulation you are God but uh but yep that's all I want to show you guys today thank you for watching I hope this gave you a little bit of an idea of what you can do with comments just to keep things easy just the way you can write python code to make it easy and understandable but I've talked for too long guys thank you thank you again uh it'd be cool if you could give me a like maybe a comment leave a yeah leave a comment that'd be nice leave a comment that's kind of a joke subscribe if you want to I'm all ears for that and I'll See You Again adios
Original Description
If you would like to support me, please like, comment & subscribe, and check me out on Patreon: https://patreon.com/johnhammond010
E-mail: johnhammond010@gmail.com
PayPal: http://paypal.me/johnhammond010
GitHub: https://github.com/JohnHammond
Site: http://www.johnhammond.org
Twitter: https://twitter.com/_johnhammond
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from John Hammond · John Hammond · 7 of 60
1
2
3
4
5
6
▶
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
Code Commentaries? PHP to JavaScript in Bash and PHP!
John Hammond
Tutorials? MySQL connection with PHP and Bash!
John Hammond
Variable Naming in Python! Happy Birthday, Linux! Nokia N900!
John Hammond
JavaScript Splits The URL!
John Hammond
HTML Tables in Python!
John Hammond
HTML, Net Shares, GML!
John Hammond
Python 08 Programming Style and Comments
John Hammond
Python 26 Object Oriented Programming
John Hammond
75 Python Tutorials, Out Now!
John Hammond
Batch 14 Mathematical Expressions
John Hammond
Batch 85 Array Append
John Hammond
Batch 86 Array Count
John Hammond
Batch 87 Array Index
John Hammond
Batch 88 Array Insert
John Hammond
Batch 89 Array Remove
John Hammond
Batch 90 Array Reverse
John Hammond
Python [colorama] 00 Installing on Linux
John Hammond
Python [colorama] 09 Cursor Position
John Hammond
Python [hashlib] 02 Algorithms
John Hammond
Python 00 Installing IDLE on Linux
John Hammond
Python [pygame] 11 Rectangular Collision Detection
John Hammond
Python [pygame] 12 Platforming Rectangular Collision Resolution
John Hammond
Python [XML-RPC] 01 Research
John Hammond
Python [pyenchant] 03 Personal Word Lists
John Hammond
FancyURLopener Authentication and User-Agent [urllib] 03
John Hammond
Python 04: PEP8 Coding
John Hammond
Python Challenge! 17 COOKIES
John Hammond
Google CTF 2016: Ernst Echidna
John Hammond
Google CTF 2016: Spotted Quoll
John Hammond
Google CTF 2016: Can you Repo It?
John Hammond
Google CTF 2016: No Big Deal
John Hammond
Google CTF 2016: In Recorded Conversation
John Hammond
Homemade CTF Challenge: 01 "Orchestra"
John Hammond
Homemade CTF Challenge: 02 "Bae's Base"
John Hammond
Homemade CTF Challenge: 03 "Web Hunt"
John Hammond
Homemade CTF Challenge: 04 "UPX"
John Hammond
Homemade CTF Challenge: 05 "The Assumption Song"
John Hammond
Homemade CTF Challenge: 06 "A Brisk Stroll"
John Hammond
Homemade CTF Challenge: 06 "I lost my password!"
John Hammond
web25 :: Mr. Robot : EKOPARTY CTF 2016
John Hammond
web50 : RFC 7230 :: EKOPARTY CTF 2016
John Hammond
misc50 : Hidden inside EKO :: EKOPARTY CTF 2016
John Hammond
Hack The Vote 2016 CTF: Sander's Fan Club [web100]
John Hammond
Hack The Vote 2016 CTF Warpspeed [forensics150]
John Hammond
Juniors CTF 2016 :: Black Suprematic Square
John Hammond
Juniors CTF 2016 :: Six Strange Tales
John Hammond
Juniors CTF 2016 :: Lost Code
John Hammond
Juniors CTF 2016 :: Here Goes!
John Hammond
Juniors CTF 2016 :: Southern Cross
John Hammond
Juniors CTF 2016 :: Clone Attack
John Hammond
Juniors CTF 2016 :: Dirty Repo
John Hammond
Juniors CTF 2016 :: Hackers Blog
John Hammond
Juniors CTF 2016 :: Voting!!!
John Hammond
Juniors CTF 2016 :: The Good, The Bad and The Junkman
John Hammond
Juniors CTF 2016 :: Stop Thief!
John Hammond
Juniors CTF 2016 :: ROFL
John Hammond
Juniors CTF 2016 :: Restriced Area
John Hammond
Juniors CTF 2016 :: Oh SSH!
John Hammond
HackCon CTF 2017 TRIVIA and BONUS Challenges
John Hammond
HackCon CTF 2017 "Bacche" Challenges
John Hammond
More on: AI Pair Programming
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Account Takeover Attacks: Why Authentication Isn’t the Real Problem
Dev.to · Sentinel Layer
When the Most Important Feature of a Migration Toolset Isn’t a Feature at All
Medium · Cybersecurity
HOW TO RECOVER CRYPTOCURRENCY LOST TO BITCOIN INVESTMENT SCAM/MALICE CYBER RECOVERY WIL DO IT
Medium · Cybersecurity
Aflac Japan Data Breach Exposes 4.38 Million Policyholder Records
Dev.to · BeyondMachines
🎓
Tutor Explanation
DeepCamp AI