Comments, Escape Sequences & Print Statement | Python Tutorial – Day #5
![*](https://i0.wp.com/allprowebdesigns.com/wp-content/uploads/2024/05/1717174470_maxresdefault.jpg?resize=840%2C430&ssl=1)
Video Title: Comments, Escape Sequences & Print Statement | Python Tutorial – Day #5
Welcome back to the 100 Days Of Code series We’ll have a close look on Comments, Escape Sequence Character & Print Statement Whenever we code in Python or any other programming language Sometimes we want to have text in the program that does not execute. Whatever we write in our program, Python interpreter tries to execute it But sometimes we would like to write some lines in our program which should not be executed. For eg. If I’m writing a program So it is possible that after 6 months I myself forget what was that program for So in this situation it would be natural for me to write few lines in my program I’d like to add some lines in it to tell future Harry what program I had written. Let’s suppose I’m working with a friend of mine Shivam and the other friend Rohan So I have to tell both of them what am I doing in this program And how this program is functioning And for this I’ll use ‘Comments’ And we’ll also learn Escape Sequence Character & Print Statement in this video Let’s move to the computer screen And let’s get started [STARTING THEME] So what I’ll do is… I’m going to open my "main.py" file here So let me open the ‘Files’ and as always I’ll open "main.py" here And here you’ll be able to see… …The output of "main.py" So if I write here "print("Hey I am a good boy") So there’s no doubt that I’m a good boy So "Hey I am a good" will be printed In fact in print statement whatever you add in double-quotes(" ") will be printed So "Hey I am a good boy" has been printed And look if I write here "Hey I am a good boy" And as I pressed ‘Enter’ here And let me write "and this viewer is also a good boy/girl" Now if I run this, so will the red line be displayed? We are skating on thin ice, What’s this error "EOL while scanning string Literal" Let me tell you what does it mean. Basically Python is saying "You know what, You wrote ‘print’ here and started with double-quotes(" ") But when you added a new line by pressing ‘Enter’. I didn’t like it" So you’ll ask Python what to do "I need a new line after the word ‘boy’ " Python will say "OK! If you need a new line… …So you must use Escape Sequence Character And you’ve to use " (back-slash)n " here like this And you don’t literally need to add this new line Just write " (back-slash)n " and Python will take care of it So you’ll say OK, I wrote "I am a good boy (back-slash)n " And when you’ll run this code So look " I am a good boy" And then "this viewer is also a good boy/girl" appeared in a new line So what was this? What was " (back-slash)n "? It was an Escape Sequence Character I’ll talk about this today And I’ll also tell you how many different kind of Escape Sequence Character are there And what are the different Escape Sequence Character But first of all I wanna tell you what are comments Let’s suppose I’m working on a code base Along with you I’m creating "codewithharry.com" And together we are working on that with a tough grind Now let’s suppose I want to tell you that the Home Page of ‘codewithharry.com’ That home page will have a new design and I’ll release that after 2 days And I want to add a comment here "Please don’t change this design or remove this line from here" I want to write here… "Hey Harry please don’t remove this line" Let’s suppose I want to add this "I’m working on it" So I just want to keep this in code base for a reminder But can you see the the Python is in a black mood His Highness is saying "What’s this. From where did this Invalid Syntax came, I know ‘Print’ and other syntaxes" But Python is saying "Hey Harry, Please don’t remove this line" I didn’t like it So when we’ll run this obviously we’ll see an error in it There’s no doubt. And you might also know what error is this But I still want to keep this line I’d say "Please" to Python and in reply it’ll say "OK! Stop crying like a baby" "OK! Stop crying like a baby. Let me tell what to do" Pythons says "I’ve a comment function in me" Comments means "You can add whatever text you want and I don’t have any business with that" You’ll say "WOW! Python you’re so great" And Python will say "Yes! For sure" What to do now? Python says "Just add a character like this and this text will become a comment" What will it become? A comment And if you mark a line as a comment… Look, Replit is doing syntax highlighting first, for you When you add this character in any IDE so it’ll be syntax highlighting In this case this comment started to be displayed in green color And look this syntax highlighting in being continued I wrote print, it is displayed in color ‘yellow’ And String literal are displayed in orangish color And these brackets are also visible to me in a different color And ‘error’ is being displayed in ‘Red’ Color so this is called syntax highlighting Which any IDE does for you "Hey Harry, Please don’t remove this line" Let’s try to run this And this time our program worked Which means I can add some text in my program or I can also add some information For eg. I want to mark that the author of this program is ‘Harry’ And let’s suppose I want to mark that this course is the 100 Days Of Code Let’s suppose I want to write this so I can do this Now let me spill the beans And what that secret is? Actually it is not a secret anymore because I’ve told you You can select multiple lines With ( Ctrl + / ) Or (Command + / ) if you’re using Mac When you’ll press these keys You can comment or uncomment to any code base So if you ever see me commenting some lines faster, so don’t ask me how I did that I would have done that with ( Ctrl + / ) So you can use ( Ctrl + / ) for commenting & uncommenting… …Single or multiple lines Man what happened to Siri! Siri I’m not talking to you So I was telling you that you can mark these multiple lines…. As comments or you can also uncomment them with the same keys OK! That’s great So this is what I’ve written here "A comment is a part of the coding file that the programmer does not want to execute Rather the programmer uses it to either explain a block of code or to avoid the execution of a specific part of code while testing." Are you understanding this? This means Let’s suppose that if I write a comment here Or let’s suppose I write a code here Suppose I want to write "print("hello world")" here And now I want to show this program to my boss And I ask him how the code is So he’ll say that this is great but… I don’t like this. So please remove "Hello World" I’ll say OK So I’ll select it and I’ll press ( Ctrl + / ) And now I can remove this code And now the boss of my boss will ask him "Why have you removed "Hello World" " So I can uncomment it And it’ll work again So this is how you can do comment or uncomment So I’ve written the same thing here with example You don’t even need to write the code Just copy this from here, paste it in your computer and run this And when you’ll do this so look You won’t see the error "this is the single line comment" and you’ll be able to see "this is the print statement" Now I’ve given an example here you can also write a comment after a line of code For eg. If you’ve written something like this I’m pasting it…. And I’ll tweak it like this Look I’ve written "print" And then what I can do is… actually I deleted " a " I should have added this bracket Now look as I’ll write "print" here And then I’ll write "Hello World" And then I can write any comment if I want to Which means my code will be executed And as it’ll get the pound(#) symbols It’ll say "OK I understood, I won’t execute this text" "I’ll ignore it" So Python interpreter will ignore " print("Hello world") " What should have happened if this symbol was not added? Obviously the error would have occurred You already know that What type error that should be? A syntax error It’ll ask what’s going on. What is this "Printing Hello World" "Print hello world" this was alright His Highness Python will say It’ll say "What have you added this "Printing hello world" I didn’t like it So you can see as I’ll add the pound(#) symbol here And then if I run so it’ll work As you can see it works Now look what I can do is.. I can comment this code out I already have told you this But I want to tell you one more thing That how you can add multi-line comments Now let me tell you the story of multi-line comments Let’s suppose someone has said to me… That… For now let’s take it’s example let me uncomment it Suppose someone ask me to uncomment these 3 lines I have to 2 ways to do that Now because I’m living in a modern world I have IDE I have Replit I have modern IDEs So I’ll select these lines & I’ll press ( Ctrl + / ) This is the shortcut provided by Replit & VScode and other modern IDEs Which helps you to do Commenting & Uncommenting easily But if I’m unable to do this so what would have I do? So for my convenience I’d have added triple single-quote(”’ ”’) and whatever I should have written in it I’m using ( Alt + ↓ ) to move the line you should also learn this shortcut In Replit all the shortcuts of VScode works so there’s no need for you to be worries And if you want to learn the shortcut of VScode so you can do the Google search I also have uploaded a video regarding VScode you watch that too But for now let’s just focus on Python So if I enclose anything in Triple single-quote(”’ ”’) So it’ll become a multi-line comment "But the comment we do earlier wasn’t the multi-line comment? " Obviously it was a type of multi-line comment So that’s what I’ve written here "that you can use pound(#) symbol for multi-line comment" But this method in which we use Triple single-quote(”’ ”’) Or you can also use Triple double-quote(""" """) Let me tell you this is also valid Program with Triple single-quote(”’ ”’) worked But program with Triple double-quote(""" """) will also work. I’ve added Triple double-quote(""" """) OK I’ll do one thing I’ll press ( shift + end ) key and then ( Ctrl + X ) and then ( Ctrl + V ).. …After selecting it Now if I run this… Even then it’ll work Can you see, It worked? Quite great! Man! So this is how we can comment & uncomment any line So I can use this shortcut ( Ctrl + / ) or in Mac ( Command + /)… …For commenting & uncommenting of line/s of code So I hope you’ve understood this Now let’s talk about Escape Sequence Character If you want to insert characters in a string For eg. Here "Hey I am a good boy". And let’s suppose I want to insert a new line character here So how will I do that? For now I’ll comment it out So that you’ll only see the output of this print statement You understood why I did this, don’t you? "Hey I am a good boy and this viewer is also a good boy/girl" Now look the tutorial that I’ve written here What have I written in it? I’ve written " To insert characters that cannot directly be used in a string, we use an escape sequence character." Essence of everything "A character that cannot directly be used in string, so we use Escape Sequence Character" For eg. If I press enter and literally add a new line character so an error will occur Because Python won’t be able to parse it If you literally add a new line in a string so it won’t be able to parse it That’s why we add new line character Now ” + ‘n’ they may seem different character But they are one This is called Escape Sequence Character ‘(back-slash)n’ is a new line character an Escape Sequence Character Whenever you add this in a string so you’ll be able to see a new line like this So if I run it now so "Hey I am a good" and the next sentence will appear in new line What about if I want to enclose "Hey I am a good boy" in double-quotes(" ") This should work, what’s the problem in this? You’ll think that and if you do so, Can you see this red line Replit already has given the sign for danger It rang the bell for danger So IDE always ring the bell for danger and ask you "don’t you dare to run this code" And if you dare so this will happen You’ll see the error "Invalid Syntax" You’ll ask "What’s the problem in this? " The problem in this is "when you started the print statement and then you started your string with double-quotes(" ") " So confusion has been created here that this string is being started from here, but is it ending here? You know this, That it is not ending here But here But our Python interpreter get’s confused It says that you’ve added double-quotes(" ") here and then here, so it must be ending here OK! It is ending here Then what it is? This is an Invalid Syntax for Python Because if this double-quotes(" ") is creating a string from here till here Then What this "good boy" is So you’ll see an error here So to avoid this we don’t use double-quote character We use ‘ " ‘ which is a double-quote Escape Sequence Character This one is a character This one is a character So now if I run this so it’ll only display double-quote(" ") "Hey I’m good boy" is in double-quote(" ") Did you see " " No. But I’ve used " " Why? Because I want to use ‘ " ‘ Which is a single character They may seem 2 but it is 1 character ‘ " ‘ which produce a single Double-quote(") in output Which is an Escape Sequence Character " An escape sequence character is a backslash followed by the character you want to insert. " "An example of a character that cannot be directly used in a string" I’ve written here If your string of print function is in a… … single-quote(‘ ‘) You cannot even use single-quote(‘ ‘) Do you get it? We’ll dive deep in this in chapter ‘Strings’ But if I’ve inserted a single quote in single-quoted string So I cannot do that I’ve to add " ‘ " Look the error has occurred But if I add " ‘ " so single-quote will appear A single-quote has appeared after "Hey I am" So this is how I can add single-quotes in strings So this was the Escape Sequence Character I hope you all have got it Now I want to spill some more beans about print statement The first thing I want to tell you is that… …You can also add multiple values in print statement Just like I can add "Hey" "6" & "7" all three of these And when I’ll run this so all three of them will be printed "Hey" "6" & "7" as you all can see in your computer screen And now its other parameter is called separator Now let’s suppose If I add "sep = Tilde(~)" character And now if I run it So you’ll be able see, when I add "sep = (~)" so this line will be separated by (~) character As you can see a Tilde(~) character has been appeared after "Hey" And then another Tilde(~) character So if you ever want to join any 3 words so you can do this just as I did So you can do this… And after this there’s another parameter "end=" Let’s suppose if I write "009"…. …In place of "end=" So what does it mean? It means if I write next ‘print’ statement And in that statement suppose I write "print("Harry") And if I run it… So look "Hey" "6" "7" will be printed And then "009" will be printed before the next print statement Ideally we use "end="…. Let’s suppose if we write "009(back-slash)n" We usually use "(back-slash)n" and we can also add "end=null" By default the function is "(back-slash)n" We also can add "end=null" You should know this too Now I’ve added "009(back-slash)n" here So whenever I run the next print statement so "009(back-slash)n" will be appended in this print statement What’s the difference between "sep" & "end"? "sep" means that how the multiple values of a single print statement will be separated But the default separator is ‘Space’ as I’ve written here Now what does "end" means? It means ‘specify what to print at end’ "What to print when this print statement will end" You can write anything here and it’ll be printed ‘By-default’ is a new line If you want to over-write this behaviour that when you enter a new print so a new line won’t be added Look as I ran this print statement A new line after this, has been printed automatically And a new line will be printed after this too if I haven’t added "end=009(back-slash)n" But because I’ve added "end=009(back-slash)n" That’s why this line will be printed after this print statement And "sep" means "separator" "What should come between multiple values in a single print statement" Great! Now there’s another argument name "file" And keep this in mind And I’ve written this here because I want you to know that you can write on ‘file’ using print statement "An object with a write method. Default is sys.stdout" Which means it’ll write on ‘stdout’ wherever you’re running it’ll be shown on console We’ll talk about the 4th argument later I’ll discuss this in the upcoming videos As we’ll progress in this course Now I’ve written another thing here "Parameters 2 and 4 are optional" 2nd & 4th parameter are optional Which means you don’t need to add ‘separator’ or ‘end’ And there’s no need for you to write ‘file’ without these your statement will work As we have already seen we haven’t used it in beginning Neither we used "end" nor we added multiple values You can also add single values But if you add multiple values even then it’ll work I hope you’re enjoying it and if you haven’t accessed this code so make sure to give it a hit And also bookmark this playlist because all videos are going to be add there Bookmark this playlist by clicking here And click here to save this play-list That’s it for this video guys Thank you so much guys for watching this video:) And I’ll see you next time
-
Sale!
Wireless WIFI Repeater Extender Amplifier Booster 300Mbps
$29.99$14.99 Add to cartWireless WIFI Repeater Extender Amplifier Booster 300Mbps
Categories: Electronics, Wi-Fi Router, Wireless Wi-Fi Extender Tags: 300Mbps, 802.11N, Amplifier, Booster, Extender, mobile wi-fi booster, Remote, WIFI, Wireless, Wireless WIFI, Wireless WIFI Repeater, Wireless WIFI Repeater Extender, Wireless WIFI Repeater Extender Amplifier, Wireless WIFI Repeater Extender Amplifier Booster, Wireless WIFI Repeater Extender Amplifier Booster 300Mbps$29.99$14.99 -
Sale!
Full RGB Light Design Gaming Headset Headphones with Mic
$24.99$14.99 Add to cartFull RGB Light Design Gaming Headset Headphones with Mic
Categories: Electronics, Gaming, Gaming Headsets Tags: Design, Full, Full RGB Light Design Gaming Headset, Full RGB Light Design Gaming Headset Headphones, Full RGB Light Design Gaming Headset Headphones with Mic, Gamer, Gaming, Gaming Headset Headphones, gaming headset wireless, Headphone, Headphones, Headset, Light, Mic, Package, RGB$24.99$14.99 -
Sale!
Wireless BlueTooth Multi-Device Keyboard Mouse Combo
$39.99$19.99 Add to cartWireless BlueTooth Multi-Device Keyboard Mouse Combo
Categories: Electronics, Gaming, Gaming Keyboards, Keyboard Mouse Combos Tags: Combo, Keyboard, keyboard mouse combos, Mouse, MultiDevice, Set, WireKeyboard Mouse Combo, Wireless, Wireless BlueTooth Keyboard Mouse Combo, Wireless BlueTooth Keyboard Mouse Combos, Wireless BlueTooth Multi-Device Keyboard Mouse Combo, Wireless BlueTooth Multi-Device Keyboard Mouse Combos$39.99$19.99 -
Sale!
High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
$199.99$139.99 Add to cartHigh Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
Categories: Gaming, Gaming Chairs Tags: Adjustable, Chair, computer chairs, Desk, Executive, Gaming, Girl, Headrest, High, High Back Leather Executive Adjustable Swivel Gaming Chair, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar, High Back Leather Executive Adjustable Swivel Gaming Chairs, Leather, Lumbar, Office, Racing, Swivel$199.99$139.99 -
Sale!
Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
$29.99$19.99 Select optionsProfessional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
SKU: N/A Categories: Electronics, Gaming, Gaming Headsets Tags: Cancelling, Gaming, Gaming Headphones with Noise Cancelling Microphone, gaming headset, Headphones, Headset, LED, Light, Mic, Microphone, Noise, Professional, Professional LED Light Wired Gaming Headphones, Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone, Wired, Wired Gaming Headphones, Wired Gaming Headphones with Noise Cancelling Microphone$29.99$19.99 -
Sale!
Gaming Desk with LED Lights USB Power Outlets and Charging Ports
$349.99$249.99 Select optionsGaming Desk with LED Lights USB Power Outlets and Charging Ports
SKU: N/A Categories: Computer Desk, Gaming, Gaming Desk Tags: and Charging Ports, Charging, Desk, Desks, Gaming, gaming desk with led lights, Gaming Desks with LED Lights, Home, LED, Lights, Monitor, Office, Outlets, Port, Power, Room, Stand, USB, USB Power Outlets, White, Workstation$349.99$249.99 -
Sale!
Wired Mixed Backlit Anti-Ghosting Gaming Keyboard
$99.99$79.99 Add to cartWired Mixed Backlit Anti-Ghosting Gaming Keyboard
Categories: Electronics, Gaming, Gaming Keyboards Tags: Antighosting, Backlit, Blue, brown, Gaming, Gaming Keyboard, gaming keyboards, gaming keyboards and mouse, Keyboard, Laptop, Switch, Wired, Wired Mixed Backlit Anti-Ghosting Gaming Keyboard, Wired Mixed Backlit Anti-Ghosting Gaming Keyboards, Wired Mixed Backlit Gaming Keyboard$99.99$79.99 -
Sale!
Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
$119.99$59.99 Add to cartWireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
Categories: Electronics, Gaming, Gaming Headsets Tags: 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, ANC, Audio, Bluetooth, Cancellation, Ear, Earphone, gaming headset, Headphones, Headset, Hi-Res Over the Ear Headphones Headset, HiRes, Noise, Wireless, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Headphones, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headsets$119.99$59.99 -
Sale!
Wired Sports Gaming Headset Earbuds with Microphone
$19.99$9.99 Select optionsWired Sports Gaming Headset Earbuds with Microphone
SKU: N/A Categories: Gaming, Gaming Headsets Tags: Accessories, Earbud, Earphone, Earphones, Gaming, gaming headset with microphone, Headphones, Headset, IOS, Microphone, Sports, Wired, Wired Sports Gaming Headset Earbuds, Wired Sports Gaming Headset Earbuds with Microphone, Wired Sports Headset Earbuds$19.99$9.99 -
Sale!
150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
$49.99$29.99 Add to cart150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
Categories: Charging Stations, Electronics Tags: 150W, 150W Charging Station, 150W Universal Multi USB Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Stations, 150W Universal Multi USB MAX Charging Station, 16 Port MAX Charging Station, 3.5A, Charger, Charging, Fast, laptop charging stations, Max, Multi, Port, Stand, Station, Universal, USB$49.99$29.99
Attendance de do sab log jaldi se!
5 video per day 20 days corce
Last wale cod ka kiya use he please btaoo koi
present Sir
can we add something which is not a number, while using end=(…), in place of 009?
What is the use of comments in this ?
Thank You Brother
Ap ki vajah se mai new life start kar paya hu ❤
Bro AP garibo ke bhagwan ho❤
Dil se thank you 🎉
Apki vajah se kitne logo ki job lag sakti hai 🎉
Thank you brother ❤
Present
who are watching in 2024 like now
Bhai mujhe modules and pip samajh nahi aaye baki ab tak sab samajh mei aaya hai
Bhai mujhe modules and pip samajh nahi aaye baki ab tak sab samajh mei aaya hai
❤
Present
p
I am present
Day 5 ✅
Present sir
harry bhai SQL 7 days challenge kijiye na love from maharashtra
Yes sir
24-5-2025 day 5 completed
I am watching this video in 2024 and really I'm very happy with this course . I want to say thank you so much Harry sir for giving us such incredible knowledge at free of cost and such a manner we can understand 🙏
Bhaya replit kis type ka software he is pr detail video banado ya paycharm me code karna sikha do😫🙏
Day 5 done ✅
bro thinks siri as his gf , siri me tumse baat nahi kr rha hu was hilarious
Hello Brother i am hear