Comments, Escape Sequences & Print Statement | Python Tutorial - Day #5

CodeWithHarry
2 Dec 202218:41

Summary

TLDRThis video script from the '100 Days Of Code' series focuses on Python's Comments, Escape Sequence Characters, and Print Statements. It explains how to use comments to add non-executable text for clarity or reminders. The script also covers escape sequences for including special characters like new lines and quotes in strings. Additionally, it explores the print statement's functionality, including how to print multiple values with customizable separators and end characters, and mentions the optional 'file' parameter for writing to files.

Takeaways

  • πŸ’‘ Comments are used in code to explain functionality or to avoid executing certain parts of the code during testing.
  • πŸ”‘ Escape Sequence Characters like '\n' and '\"' allow programmers to include characters in strings that would otherwise cause errors.
  • πŸ“ Print statements in Python can print text enclosed in double quotes by using the escape character '\"'.
  • 🚫 The error 'EOL while scanning string literal' occurs when a new line is introduced in a string without using an escape sequence.
  • βœ… The 'print' function can print multiple values separated by a specified separator, defaulting to a space.
  • πŸ”„ The 'end' parameter in 'print' allows customization of what is printed at the end of a statement, defaulting to a new line '\n'.
  • πŸ“ Comments can be added to code using the '#' symbol for single-line comments or triple quotes for multi-line comments.
  • πŸ› οΈ IDEs like Replit provide shortcuts like 'Ctrl + /' or 'Command + /' for commenting and uncommenting lines of code.
  • πŸ“‘ The 'file' parameter in 'print' allows writing directly to a file object, with 'sys.stdout' as the default for console output.
  • πŸ” The video emphasizes the importance of understanding comments and escape sequences for effective Python programming.

Q & A

  • What is the purpose of comments in programming?

    -Comments are used in programming to add text that the interpreter does not execute. They are helpful for explaining blocks of code, reminding the programmer or other developers about the purpose and functionality of the code, and for avoiding the execution of specific parts of code during testing.

  • How do you create a single-line comment in Python?

    -In Python, a single-line comment is created by prefixing the comment text with a hash symbol (#). Anything following the hash symbol on the same line is ignored by the Python interpreter.

  • What is an Escape Sequence Character and why is it used?

    -An Escape Sequence Character is a sequence introduced by a backslash (\) that represents a special character or instruction. It is used to include characters in a string that cannot be directly used, such as a new line (\n) or a double quote (\").

  • How do you print a new line in a string using an Escape Sequence Character?

    -To print a new line in a string, you use the Escape Sequence Character '\n'. When this sequence is included in a string, Python will interpret it as a command to start a new line when the string is printed.

  • What is the default behavior of the 'end' parameter in the print statement?

    -The default behavior of the 'end' parameter in the print statement is to print a new line (\n) at the end of the output. This means that by default, when a print statement is executed, the cursor moves to the next line.

  • How can you change the default separator in the print statement?

    -You can change the default separator in the print statement by using the 'sep' parameter followed by the separator character you want to use. By default, the separator is a space.

  • What is the purpose of the 'file' parameter in the print statement?

    -The 'file' parameter in the print statement specifies a file object to which the output should be directed. By default, it is set to 'sys.stdout', which means the output is directed to the standard output, typically the console.

  • How do you print multiple values in a single print statement?

    -You can print multiple values in a single print statement by separating them with commas. The 'sep' parameter can be used to specify the separator between these values.

  • What is the difference between 'sep' and 'end' parameters in the print statement?

    -The 'sep' parameter specifies the separator between multiple values in a single print statement, while the 'end' parameter specifies what to print at the end of the print statement. The default separator is a space, and the default end character is a new line (\n).

  • How can you prevent the automatic new line after a print statement?

    -You can prevent the automatic new line after a print statement by setting the 'end' parameter to an empty string ('end=""'). This will cause the next print statement to start on the same line.

  • What is the significance of the shortcut (Ctrl + /) mentioned in the script?

    -The shortcut (Ctrl + /) is used to quickly comment or uncomment lines of code in many Integrated Development Environments (IDEs). This is a time-saving feature that allows developers to toggle comments on or off for selected lines of code.

Outlines

00:00

πŸ’» Introduction to Comments and Print Statements

The script begins with a discussion on the importance of comments in programming, particularly in Python. Comments are lines of code that the interpreter ignores, allowing programmers to leave notes or explanations within the code without affecting its execution. The video introduces the concept of escape sequence characters, which are used to include special characters within strings that would otherwise cause errors, such as a new line. The presenter demonstrates how to use the print statement to output text to the console, and how to use escape sequences to include new lines within the printed text. The example of a syntax error due to an unclosed string literal is also discussed, along with the solution of using the escape sequence ' ' to indicate a new line.

05:03

πŸ“ Understanding Comments and Syntax Highlighting

This section delves deeper into the concept of comments, explaining how they serve as a reminder or explanation within the code. The presenter illustrates how to write comments in Python using the pound (#) symbol and how to use the IDE's functionality to comment or uncomment multiple lines of code quickly using the shortcut Ctrl + /. The script also mentions the visual aid of syntax highlighting in IDEs, which helps programmers distinguish different elements of the code, such as comments, strings, and errors, by displaying them in different colors.

10:05

πŸ”‘ Exploring Multi-line Comments and Escape Sequences

The script continues with a discussion on multi-line comments, which allow programmers to comment out multiple lines of code at once. It explains how to use triple single-quotes (''' ''') or triple double-quotes (""" """) to create multi-line comments. The presenter also touches upon the use of escape sequences to include characters like double-quotes or single-quotes within strings that would otherwise cause syntax errors. The concept of an escape sequence character, which is a backslash followed by the character to be inserted, is clarified with examples.

15:06

πŸ–¨οΈ Advanced Print Statement Features

In this part of the script, the presenter explores advanced features of the print statement. It covers how to print multiple values at once and how to use the 'sep' parameter to define a custom separator between values. The 'end' parameter is introduced, which allows the programmer to specify what should be printed at the end of the print statement, overriding the default behavior of adding a new line. The script also mentions the optional 'file' parameter, which can be used to write the output to a file instead of the console, and notes that parameters 2 and 4 ('sep' and 'end') are optional and can be omitted if not needed.

Mindmap

Keywords

πŸ’‘Comments

Comments in programming are lines of code that are ignored by the compiler or interpreter and not executed. They are used to explain or clarify the code, making it more readable and maintainable. In the video, the presenter uses comments to leave notes for future reference or to communicate with other developers. For example, the presenter wants to remind a colleague not to remove a specific line of code by writing a comment.

πŸ’‘Escape Sequence Character

Escape sequences are characters that are prefixed by a backslash to signal that the following character should be interpreted differently, such as a newline or a tab. In the video, the presenter explains how to use escape sequences to insert special characters into strings, like a new line (\n) or a double quote ("), which cannot be directly included in the string.

πŸ’‘Print Statement

A print statement is a fundamental part of programming used to output text or values to the screen. The video discusses how to use print statements in Python, including how to print strings and handle errors that occur when using incorrect syntax, such as forgetting to close a string with the correct quotation mark.

πŸ’‘Syntax Highlighting

Syntax highlighting is a feature of code editors that displays text, specifically source code, in different colors and fonts according to the category of terms. This helps in identifying and distinguishing elements like comments, strings, and errors. In the video, the presenter mentions how different parts of the code are highlighted in various colors, aiding in code readability.

πŸ’‘EOL while scanning string literal

EOL stands for 'End Of Line'. This error occurs in Python when the interpreter reaches a newline character while parsing a string that hasn't been properly closed. The video script describes this error happening when the presenter tries to split a string across multiple lines without using an escape sequence for the newline.

πŸ’‘IDE

IDE stands for Integrated Development Environment, a software application that provides comprehensive facilities to programmers for software development. The video mentions using an IDE to write and run Python code, highlighting features like syntax highlighting and shortcuts for commenting and uncommenting code.

πŸ’‘Syntax Error

A syntax error occurs when the code does not conform to the rules of the programming language's syntax. In the video, the presenter discusses how syntax errors can happen, such as when a string is not properly closed, and how to resolve them.

πŸ’‘Multi-line Comments

Multi-line comments allow programmers to comment out multiple lines of code at once. The video explains how to create multi-line comments in Python using triple quotes, either single (''') or double ("""), which can span multiple lines.

πŸ’‘Separator

In the context of the print statement, the separator is a parameter that defines the string that will be printed between values in the print statement. The video shows how to use the sep parameter to change the default separator, which is a space, to something else, like a tilde (~).

πŸ’‘End

The end parameter in a print statement specifies what is printed at the end of the output. By default, it is a newline character, but it can be changed to anything. The video demonstrates how to use the end parameter to avoid adding a newline after the print statement, instead appending a custom string like '009'.

πŸ’‘File

The file parameter in a print statement allows the programmer to specify a file object to which the output should be written. By default, it is sys.stdout, which means the output will be printed to the console. The video briefly mentions this parameter, indicating that it will be discussed in more detail in future videos.

Highlights

Introduction to Comments, Escape Sequence Character & Print Statement in Python

Explanation of why comments are necessary in code

How to use comments to explain code to future self or colleagues

Demonstration of the print statement and its output

Error explanation: EOL while scanning string literal

Introduction to Escape Sequence Characters

How to use the newline Escape Sequence Character (back-slash)n

Definition and explanation of comments in programming

How to use comments to leave notes within the codebase

Error handling when attempting to write comments without proper syntax

How to use the comment function in Python

Syntax highlighting in IDEs and its benefits

Shortcut (Ctrl + /) for commenting and uncommenting in code

Explanation of single-line and multi-line comments

How to use triple single-quotes for multi-line comments

Demonstration of the print statement with multiple values

Introduction to the 'sep' parameter in the print statement

Introduction to the 'end' parameter in the print statement

How to use the 'file' parameter in the print statement

Clarification that parameters 2 and 4 in the print statement are optional

Invitation to bookmark the playlist for future videos in the series

Transcripts

play00:00

Welcome back to the 100 Days Of Code series

play00:03

We'll have a close look on Comments, Escape Sequence Character & Print Statement

play00:08

Whenever we code in Python or any other programming language

play00:12

Sometimes we want to have text in the program that does not execute.

play00:16

Whatever we write in our program, Python interpreter tries to execute it

play00:19

But sometimes we would like to write some lines in our program which should not be executed.

play00:23

For eg. If I'm writing a program

play00:26

So it is possible that after 6 months I myself forget what was that program for

play00:29

So in this situation it would be natural for me to write few lines in my program

play00:33

I'd like to add some lines in it to tell future Harry what program I had written.

play00:39

Let's suppose I'm working with a friend of mine Shivam and the other friend Rohan

play00:45

So I have to tell both of them what am I doing in this program

play00:49

And how this program is functioning

play00:52

And for this I'll use 'Comments'

play00:54

And we'll also learn Escape Sequence Character & Print Statement in this video

play00:57

Let's move to the computer screen And let's get started

play01:00

[STARTING THEME]

play01:10

So what I'll do is... I'm going to open my "main.py" file here

play01:15

So let me open the 'Files' and as always I'll open "main.py" here

play01:20

And here you'll be able to see...

play01:25

...The output of "main.py"

play01:26

So if I write here "print("Hey I am a good boy")

play01:30

So there's no doubt that I'm a good boy

play01:33

So "Hey I am a good" will be printed

play01:36

In fact in print statement whatever you add in double-quotes(" ") will be printed

play01:42

So "Hey I am a good boy" has been printed

play01:44

And look if I write here "Hey I am a good boy"

play01:48

And as I pressed 'Enter' here

play01:50

And let me write "and this viewer is also a good boy/girl"

play01:58

Now if I run this, so will the red line be displayed?

play02:02

We are skating on thin ice, What's this error "EOL while scanning string Literal"

play02:06

Let me tell you what does it mean.

play02:08

Basically Python is saying "You know what,

play02:11

You wrote 'print' here and started with double-quotes(" ")

play02:14

But when you added a new line by pressing 'Enter'. I didn't like it"

play02:19

So you'll ask Python what to do "I need a new line after the word 'boy' "

play02:23

Python will say "OK! If you need a new line...

play02:27

...So you must use Escape Sequence Character

play02:32

And you've to use " (back-slash)n " here like this

play02:35

And you don't literally need to add this new line

play02:38

Just write " (back-slash)n " and Python will take care of it

play02:41

So you'll say OK, I wrote "I am a good boy (back-slash)n "

play02:45

And when you'll run this code

play02:47

So look " I am a good boy"

play02:49

And then "this viewer is also a good boy/girl" appeared in a new line

play02:53

So what was this?

play02:55

What was " (back-slash)n "?

play02:56

It was an Escape Sequence Character

play02:58

I'll talk about this today

play02:59

And I'll also tell you how many different kind of Escape Sequence Character are there

play03:03

And what are the different Escape Sequence Character

play03:06

But first of all I wanna tell you what are comments

play03:09

Let's suppose I'm working on a code base

play03:11

Along with you I'm creating "codewithharry.com"

play03:14

And together we are working on that with a tough grind

play03:19

Now let's suppose I want to tell you that the Home Page of 'codewithharry.com'

play03:24

That home page will have a new design and I'll release that after 2 days

play03:27

And I want to add a comment here "Please don't change this design or remove this line from here"

play03:32

I want to write here...

play03:34

"Hey Harry please don't remove this line"

play03:39

Let's suppose I want to add this

play03:43

"I'm working on it"

play03:45

So I just want to keep this in code base for a reminder

play03:48

But can you see the the Python is in a black mood

play03:51

His Highness is saying "What's this. From where did this Invalid Syntax came, I know 'Print' and other syntaxes"

play03:58

But Python is saying "Hey Harry, Please don't remove this line" I didn’t like it

play04:03

So when we'll run this obviously we'll see an error in it

play04:06

There's no doubt. And you might also know what error is this

play04:10

But I still want to keep this line

play04:12

I'd say "Please" to Python and in reply it'll say "OK! Stop crying like a baby"

play04:15

"OK! Stop crying like a baby. Let me tell what to do"

play04:18

Pythons says "I've a comment function in me"

play04:21

Comments means "You can add whatever text you want and I don't have any business with that"

play04:26

You'll say "WOW! Python you're so great"

play04:29

And Python will say "Yes! For sure"

play04:32

What to do now?

play04:33

Python says "Just add a character like this and this text will become a comment"

play04:37

What will it become? A comment

play04:39

And if you mark a line as a comment...

play04:42

Look, Replit is doing syntax highlighting first, for you

play04:45

When you add this character in any IDE so it'll be syntax highlighting

play04:48

In this case this comment started to be displayed in green color

play04:52

And look this syntax highlighting in being continued

play04:54

I wrote print, it is displayed in color 'yellow'

play04:56

And String literal are displayed in orangish color

play04:59

And these brackets are also visible to me in a different color

play05:03

And 'error' is being displayed in 'Red' Color so this is called syntax highlighting

play05:07

Which any IDE does for you

play05:10

"Hey Harry, Please don’t remove this line"

play05:12

Let's try to run this

play05:15

And this time our program worked

play05:16

Which means I can add some text in my program or I can also add some information

play05:21

For eg. I want to mark that the author of this program is 'Harry'

play05:25

And let's suppose I want to mark that this course is the 100 Days Of Code

play05:33

Let's suppose I want to write this so I can do this

play05:37

Now let me spill the beans

play05:39

And what that secret is? Actually it is not a secret anymore because I've told you

play05:42

You can select multiple lines

play05:44

With ( Ctrl + / ) Or (Command + / ) if you're using Mac

play05:49

When you'll press these keys

play05:50

You can comment or uncomment to any code base

play05:54

So if you ever see me commenting some lines faster, so don't ask me how I did that

play05:59

I would have done that with ( Ctrl + / )

play06:03

So you can use ( Ctrl + / ) for commenting & uncommenting...

play06:08

...Single or multiple lines

play06:12

Man what happened to Siri! Siri I'm not talking to you

play06:15

So I was telling you that you can mark these multiple lines....

play06:21

As comments or you can also uncomment them with the same keys

play06:25

OK! That's great

play06:27

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

play06:33

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."

play06:39

Are you understanding this? This means

play06:42

Let's suppose that if I write a comment here

play06:45

Or let's suppose I write a code here

play06:47

Suppose I want to write "print("hello world")" here

play06:52

And now I want to show this program to my boss

play06:56

And I ask him how the code is

play06:58

So he'll say that this is great but...

play07:00

I don't like this. So please remove "Hello World"

play07:03

I'll say OK

play07:04

So I'll select it and I'll press ( Ctrl + / )

play07:07

And now I can remove this code

play07:09

And now the boss of my boss will ask him "Why have you removed "Hello World" "

play07:15

So I can uncomment it

play07:18

And it'll work again

play07:20

So this is how you can do comment or uncomment

play07:24

So I've written the same thing here with example You don't even need to write the code

play07:28

Just copy this from here, paste it in your computer and run this

play07:32

And when you'll do this so look

play07:34

You won't see the error "this is the single line comment" and you'll be able to see "this is the print statement"

play07:39

Now I've given an example here you can also write a comment after a line of code

play07:44

For eg. If you've written something like this

play07:47

I'm pasting it....

play07:50

And I'll tweak it like this

play07:52

Look I've written "print"

play07:53

And then what I can do is... actually I deleted " a "

play07:57

I should have added this bracket

play07:58

Now look as I'll write "print" here

play08:01

And then I'll write "Hello World"

play08:03

And then I can write any comment if I want to

play08:08

Which means my code will be executed

play08:10

And as it'll get the pound(#) symbols It'll say "OK I understood, I won't execute this text"

play08:15

"I'll ignore it"

play08:17

So Python interpreter will ignore " print("Hello world") "

play08:21

What should have happened if this symbol was not added?

play08:23

Obviously the error would have occurred You already know that

play08:26

What type error that should be? A syntax error

play08:27

It'll ask what's going on. What is this "Printing Hello World"

play08:30

"Print hello world" this was alright His Highness Python will say

play08:33

It'll say "What have you added this "Printing hello world" I didn't like it

play08:38

So you can see as I'll add the pound(#) symbol here

play08:44

And then if I run so it'll work

play08:47

As you can see it works

play08:49

Now look what I can do is.. I can comment this code out I already have told you this

play08:54

But I want to tell you one more thing

play08:56

That how you can add multi-line comments

play08:58

Now let me tell you the story of multi-line comments

play09:00

Let's suppose someone has said to me...

play09:03

That...

play09:04

For now let's take it's example let me uncomment it

play09:07

Suppose someone ask me to uncomment these 3 lines

play09:10

I have to 2 ways to do that

play09:11

Now because I'm living in a modern world

play09:14

I have IDE I have Replit I have modern IDEs

play09:18

So I'll select these lines & I'll press ( Ctrl + / )

play09:20

This is the shortcut provided by Replit & VScode and other modern IDEs

play09:25

Which helps you to do Commenting & Uncommenting easily

play09:30

But if I'm unable to do this so what would have I do?

play09:32

So for my convenience I'd have added triple single-quote(''' ''') and whatever I should have written in it

play09:37

I'm using ( Alt + ↓ ) to move the line you should also learn this shortcut

play09:43

In Replit all the shortcuts of VScode works so there's no need for you to be worries

play09:48

And if you want to learn the shortcut of VScode so you can do the Google search

play09:52

I also have uploaded a video regarding VScode you watch that too

play09:54

But for now let's just focus on Python

play09:56

So if I enclose anything in Triple single-quote(''' ''')

play10:00

So it'll become a multi-line comment

play10:02

"But the comment we do earlier wasn't the multi-line comment? "

play10:05

Obviously it was a type of multi-line comment

play10:07

So that's what I've written here "that you can use pound(#) symbol for multi-line comment"

play10:12

But this method in which we use Triple single-quote(''' ''')

play10:14

Or you can also use Triple double-quote(""" """) Let me tell you this is also valid

play10:18

Program with Triple single-quote(''' ''') worked

play10:20

But program with Triple double-quote(""" """) will also work. I've added Triple double-quote(""" """)

play10:24

OK I'll do one thing I'll press ( shift + end ) key and then ( Ctrl + X ) and then ( Ctrl + V )..

play10:29

...After selecting it

play10:30

Now if I run this...

play10:31

Even then it'll work

play10:33

Can you see, It worked?

play10:36

Quite great! Man!

play10:39

So this is how we can comment & uncomment any line

play10:43

So I can use this shortcut ( Ctrl + / ) or in Mac ( Command + /)...

play10:50

...For commenting & uncommenting of line/s of code

play10:55

So I hope you've understood this

play10:57

Now let's talk about Escape Sequence Character

play11:01

If you want to insert characters in a string

play11:05

For eg. Here "Hey I am a good boy". And let's suppose I want to insert a new line character here

play11:13

So how will I do that?

play11:14

For now I'll comment it out

play11:17

So that you'll only see the output of this print statement

play11:21

You understood why I did this, don't you?

play11:25

"Hey I am a good boy and this viewer is also a good boy/girl"

play11:30

Now look the tutorial that I've written here What have I written in it?

play11:34

I've written " To insert characters that cannot directly be used in a string, we use an escape sequence character."

play11:40

Essence of everything

play11:41

"A character that cannot directly be used in string, so we use Escape Sequence Character"

play11:47

For eg.

play11:48

If I press enter and literally add a new line character so an error will occur

play11:52

Because Python won't be able to parse it

play11:54

If you literally add a new line in a string so it won't be able to parse it

play11:57

That's why we add new line character

play12:00

Now '\' + 'n' they may seem different character

play12:02

But they are one

play12:04

This is called Escape Sequence Character

play12:06

'(back-slash)n' is a new line character an Escape Sequence Character

play12:10

Whenever you add this in a string so you'll be able to see a new line like this

play12:15

So if I run it now so "Hey I am a good" and the next sentence will appear in new line

play12:20

What about if I want to enclose "Hey I am a good boy" in double-quotes(" ")

play12:25

This should work, what's the problem in this?

play12:28

You'll think that and if you do so, Can you see this red line

play12:31

Replit already has given the sign for danger It rang the bell for danger

play12:36

So IDE always ring the bell for danger and ask you "don't you dare to run this code"

play12:40

And if you dare so this will happen

play12:43

You'll see the error "Invalid Syntax"

play12:45

You'll ask "What's the problem in this? "

play12:47

The problem in this is "when you started the print statement and then you started your string with double-quotes(" ") "

play12:52

So confusion has been created here that this string is being started from here, but is it ending here?

play12:58

You know this, That it is not ending here

play13:00

But here

play13:01

But our Python interpreter get's confused

play13:04

It says that you've added double-quotes(" ") here and then here, so it must be ending here

play13:09

OK! It is ending here Then what it is?

play13:11

This is an Invalid Syntax for Python

play13:14

Because if this double-quotes(" ") is creating a string from here till here

play13:17

Then What this "good boy" is

play13:19

So you'll see an error here

play13:21

So to avoid this we don't use double-quote character

play13:24

We use ' \" ' which is a double-quote Escape Sequence Character

play13:30

This one is a character

play13:32

This one is a character

play13:33

So now if I run this so it'll only display double-quote(" ")

play13:36

"Hey I'm good boy" is in double-quote(" ")

play13:40

Did you see " \ " No.

play13:42

But I've used " \ "

play13:45

Why?

play13:46

Because I want to use ' \" '

play13:48

Which is a single character

play13:50

They may seem 2 but it is 1 character

play13:52

' \" ' which produce a single Double-quote(") in output

play13:56

Which is an Escape Sequence Character

play13:59

" An escape sequence character is a backslash \ followed by the character you want to insert. "

play14:04

"An example of a character that cannot be directly used in a string" I've written here

play14:09

If your string of print function is in a...

play14:13

... single-quote(' ')

play14:15

You cannot even use single-quote(' ')

play14:17

Do you get it?

play14:18

We'll dive deep in this in chapter 'Strings'

play14:21

But if I've inserted a single quote in single-quoted string So I cannot do that

play14:25

I've to add " \' "

play14:27

Look the error has occurred

play14:28

But if I add " \' " so single-quote will appear

play14:31

A single-quote has appeared after "Hey I am"

play14:34

So this is how I can add single-quotes in strings

play14:37

So this was the Escape Sequence Character I hope you all have got it

play14:41

Now I want to spill some more beans about print statement

play14:45

The first thing I want to tell you is that...

play14:49

...You can also add multiple values in print statement

play14:51

Just like I can add "Hey" "6" & "7" all three of these

play14:54

And when I'll run this so all three of them will be printed

play14:57

"Hey" "6" & "7" as you all can see in your computer screen

play15:02

And now its other parameter is called separator

play15:06

Now let's suppose If I add "sep = Tilde(~)" character

play15:10

And now if I run it

play15:11

So you'll be able see, when I add "sep = (~)" so this line will be separated by (~) character

play15:17

As you can see a Tilde(~) character has been appeared after "Hey"

play15:20

And then another Tilde(~) character

play15:22

So if you ever want to join any 3 words so you can do this just as I did

play15:29

So you can do this...

play15:30

And after this there's another parameter "end="

play15:34

Let's suppose if I write "009"....

play15:37

...In place of "end="

play15:39

So what does it mean?

play15:40

It means if I write next 'print' statement

play15:44

And in that statement suppose I write "print("Harry")

play15:46

And if I run it...

play15:48

So look "Hey" "6" "7" will be printed

play15:51

And then "009" will be printed before the next print statement

play15:55

Ideally we use "end="....

play15:57

Let's suppose if we write "009(back-slash)n"

play16:00

We usually use "(back-slash)n" and we can also add "end=null"

play16:04

By default the function is "(back-slash)n"

play16:06

We also can add "end=null"

play16:08

You should know this too

play16:10

Now I've added "009(back-slash)n" here

play16:12

So whenever I run the next print statement so "009(back-slash)n" will be appended in this print statement

play16:19

What's the difference between "sep" & "end"?

play16:21

"sep" means that how the multiple values of a single print statement will be separated

play16:28

But the default separator is 'Space' as I've written here

play16:34

Now what does "end" means? It means 'specify what to print at end'

play16:37

"What to print when this print statement will end"

play16:40

You can write anything here and it'll be printed

play16:42

'By-default' is a new line

play16:45

If you want to over-write this behaviour that when you enter a new print so a new line won't be added

play16:50

Look as I ran this print statement

play16:53

A new line after this, has been printed automatically

play16:55

And a new line will be printed after this too if I haven't added "end=009(back-slash)n"

play17:00

But because I've added "end=009(back-slash)n"

play17:03

That's why this line will be printed after this print statement

play17:07

And "sep" means "separator"

play17:09

"What should come between multiple values in a single print statement"

play17:14

Great!

play17:15

Now there's another argument name "file"

play17:16

And keep this in mind

play17:19

And I've written this here because I want you to know that you can write on 'file' using print statement

play17:24

"An object with a write method. Default is sys.stdout"

play17:28

Which means it'll write on 'stdout' wherever you're running it'll be shown on console

play17:33

We'll talk about the 4th argument later I'll discuss this in the upcoming videos

play17:39

As we'll progress in this course

play17:41

Now I've written another thing here "Parameters 2 and 4 are optional"

play17:45

2nd & 4th parameter are optional

play17:47

Which means you don't need to add 'separator' or 'end'

play17:52

And there's no need for you to write 'file' without these your statement will work

play17:55

As we have already seen we haven't used it in beginning

play17:57

Neither we used "end" nor we added multiple values

play18:00

You can also add single values

play18:02

But if you add multiple values even then it'll work

play18:06

I hope you're enjoying it and if you haven't accessed this code so make sure to give it a hit

play18:10

And also bookmark this playlist because all videos are going to be add there

play18:14

Bookmark this playlist by clicking here

play18:18

And click here to save this play-list

play18:21

That's it for this video guys

play18:22

Thank you so much guys for watching this video:)

play18:25

And I'll see you next time

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Python CodingCommentsEscape SequencesPrint StatementCoding TutorialSyntax HighlightingIDE TipsString LiteralsDebugging ErrorsProgramming Basics