[no audio]
Friends here
we are going to discuss about some of these special characters
of Python, right. To explain this, right,
I am going to take one simple Python program or Python Script.
Let me open my terminal first.
[no audio]
Okay, I am moving into 'Desktop'. There actually I have a directory
called 'PythonScripts'.
So here I am going to write a Python Script name called
'special_char.py'.
[no audio]
First I'm going to write one simple Python
program. The purpose of that Python program is simply to
print some information like, "Welcome to python scripting".
Right. I am going to write that one.
Let me write it. 'print'
[no audio]
"Welcome to python scripting".
So what you are doing guys? You are simply printing some string,
okay. So whenever if you want to print a string using 'print'
statement you have to write your string inside of quotation
with your 'print', right?
That's okay. First
let me save it,
[no audio]
and run it. Already
we know how to run your Python scripts, right?
So this is your Python Script.
I am going to run our Python Script in this way.
Yes, you are getting some output.
Guys now I want to print output like
[no audio]
"Welcome to python scripting",
and in the next line I want to write, "This is about special
characters of your python".
So what I have to do? I need to include one more line called,
Right. Let me write it one more line.
So I want to print one more line.
So I have to use one more 'print' statement.
So, "We are working with some special characters".
That's it.
Let me save this,
and run it. Before running just see what is your code.
So this is your code. You are having two lines of Python Script.
So those two lines are simply to print some string.
So whenever if you have a 'print', simply it will print whatever
there inside of your quotations as of now, right.
Let me run it.
Yes, I'm getting two lines of information.
So guys actually you are using immediately two 'print' statements,
first line 'print', second line 'print'. You're printing information
with two 'print' statements. Instead of that
I can use only one 'print' statement,
I can also print this line,
I mean this information, right?
What I will do is, so you know how to comment Python Script lines,
right. You can skip, you can comment any line.
Now, I don't want to run these two lines
that's why I'm commenting. Now,
I am going to write one single 'print' statement in this way.
[no audio]
"Welcome to python scripting", then I am writing
"We are working with special chars".
Yes, this will also work and you will get your output, right.
So before getting output just observe your script once.
Let me clear our screen. Yeah.
This is your script output you're getting. But my intention
is I want to print this information in one line, and this
information in next line. Here actually we're getting both the
information in a single line.
So at that time what I can do is
[no audio]
open your script once.
[no audio]
From which information you want to print that information
in the next line, just before that write "/n",
and save it.
[no audio]
Right. Now this is your script.
We have only one line guys.
First two lines are commented.
That means your Python Script won't execute first two lines.
Now, I am running. You are getting your output in two lines. Now here
"/n" is the special character, and it is called new line.
So whenever if you include "/n", after "/n" whatever you are
having that info you will get in the next line, like this.
Right. So guys you are having some special characters.
Let me discuss at least some of them and while going forward
we will discuss remaining things based on requirements, right.
See first thing,
[no audio]
special characters you have to write always your special
characters inside of your quotations.
[no audio]
Write special chars only inside of quotes. That quotes
maybe single quotations or some double quotations. You can
use any one of that, right. Now
very first one what we are discussing, is this is called
'New line',
[no audio]
right. Now, let me go with the "/b", and this is
called backspace.
[no audio]
See how it is going to work.
So guys whatever you are having inside of your script that
thing you can also run from your Python Shell. Just simply
type on your command line 'python', and then you will enter
into your Python Shell.
Let me copy this line and paste it on your Python command
line or Python Shell, and 'Enter'. See the output.
Right. Now from here
I am explaining your special characters.
So whatever I am going to type here same thing
you can write into one file, and I can execute.
I mean you can create one Python Script and you can execute
it. Let me 'print' simply
"Hello World". You're getting some output no.
Now what I am doing is just before your "World"
I am writing "/b", and see the output. There is no space between
your two words.
Right. The reason is "/b" will send your cursor position back, one
position back.
That's why after "Hello"
actually you have a space, right? That space will be removed
because your cursor is coming back one position.
That is the purpose of "/b".
So if I write two "/b", right, because of one "/b" your cursor
will come back one position, and second one more position
back, see that.
'o' is missing. So actually first your python will type
"Hello", after that because of this "/b" your cursor will come
to this position, again one more "/b", because of that your
cursor will come to this "o" position, and from there onwards
your next word will type.
If I write three "/b",
[no audio]
see the output.
So your cursor will come back three position,
positions, and from there
it will try to overwrite your existing information with the
new information whatever it is
there after your "/b".
[no audio]
Right. So that is the "/b". Now "/t". "/t" - tab. You know tab. What
is the purpose of tab, right?
Let me show you that here, it's very simple.
So without a tab what is the output, and with the tab
what is the output? Just you're providing tab space
in the output. That's it.
[no audio]
Right. Fine. Next thing.
[no audio]
See guys suppose I want to print information like this, 'print("
[no audio]
python's
[no audio]
class")', something like that.
Yes, it's working perfectly, right? Now first observe this
one. So in your 'print' statements you can also use instead
of double quotation
you can also use single quotations.
No problem, it will work.
But in this case if I try to write "python's", you will get a syntax
error. "invalid syntax", you are getting. The reason is,
so 'print', you are printing some string. String should be there
inside of your quotation.
Actually your Python will take this as a starting quotation,
and this as the ending quotation. Then what about this information?
So now what you have to do is, this is the starting quotation,
and this is ending quotation, and you have to escape here.
Right. Your Python should not consider this as a quotation,
single quotation. Then in that case you have to write a "\", escape
symbol "\". Now because of that what it will do is, your Python
simply will skip this as a quotation. It will take this as
some letter, some character, and it will preserve in the output.
See the output.
Now it is not like a quotation.
It is like other than quotation some character.
[no audio]
Right. Fine. Not only that,
sometimes you have to write, suppose
"This is a python class", and you want to write 'python' in double quotations
[no audio]
So you know, this is starting and this is ending,
but between if you have any quotations, right you can escape
from that simply. As of now if I run you will get an error
guys. I mean an "invalid syntax" you will get. Only starting
and ending quotation is for your string. In middle
if you get any quotations you have to escape from the purpose
of your quotations. At that time you have to write simply "\" so that
your quotations will be considered as any character other than
your quotations. Now see that. Right. Now "\" is for escape symbol.
[no audio]
Okay, then.
[no audio]
Let me do one thing.
So I will do one thing guys.
Let me go with my desktop.
It may be any folder.
So here what I am doing is I'm creating a new folder called
[no audio]
"new" itself, right. So I am going to create simply "new".
Then what is the path of this?
So this is the path, right?
Let me print this path with your Python. Because that is a
string I can print it but see the output what you are getting.
[no audio]
Right. See guys, whenever if you are providing your path in your
Python that too only Windows path because in Windows you have
this "\", but whereas in Linux you have "/",
so this is the problem. Already
we know this "\" is for our escape symbol purpose, but in
your Python, I mean in the path, in Windows path you have that symbol
Right. Now you have to escape from that symbol.
So actually, you know to escape from any character you're
using Escape symbol.
This "\" in your Python. The same way you can use in your
Python Windows path also in this way,
or simply remember that whenever if you are providing Windows
path, you have to write two slashes manually. If your Python
script is going to find any path through logic, you don't
for that you don't need to worry, but if you are providing
manually some Windows path while working with your Python
scripts there you have to write two slashes in your path
then only it will work.
[no audio]
Right. So this is very, very important guys. Those who are working Python
[no audio]
for Windows,
okay. If you are working with your Windows using Python,
so whenever if you are entering path manually, Windows path,
only Windows path, there is no problem with your Unix Systems
paths, then instead of "\"
you have to provide "\\".
Right.
[no audio]
Okay, so guys there is, there are some other symbols
as well like "\a", it will create an alert sound. Alert sound, right.
[no audio]
Okay. So we have some more things. While going forward
we'll discuss some of other special characters as well.
So for time being you have to know this minimum special characters
to work with your Python, right?
Okay guys, thank you for watching this video.
[no audio]