[no audio]
Hi friends, here
we are going to write very simple Python Script, and that
is simply printing some message.
So here I am going to print "Hello World!"
using your Python Script, and what about the script you are
going to write? That I am going to write using 'vim', and 'Default IDLE'.
So here we are going to see a simple Python Script
by using either 'vim' editor, or 'Default IDLE', right.
Let me open first of all
my command line on my Windows operating system.
You can write same program, same script on your Linux or any
Unix-like systems as well, right?
So guys I'm moving into my desktop, there
I am going to create 'PythonScripts' directory.
Let me enter into that. See as of now
you don't have anything in this directory.
Right. See if you want to use 'vim' editor,
first of all you should have 'vim' on your host.
So in our previous video we have seen different types of
editors, and I have given a link to install 'vim' editor on your
Windows operating system.
Anyway by default 'vi' is there on your Unix-like systems.
You can use 'vi' on your Unix-like systems. But in Windows
you don't have 'vi', but you can install 'vim', right?
So I already installed that. Now
let me run 'vim', simply 'hello_word.py'. You can take any
name guys, any script name you can take, and extension is '.py'
just to know that that is a Python Script or Python program.
Now, let me enter 'vim ', some program name '.py'.
Right. Now I am going to open your 'vim' editor.
I opened that, right. See guys my intention is I have to write a
some Python Script or Python program, and if I run that program
I have to get output as simply some "Hello World!", right.
So to print the something, to print some text or message or
string in your Python
you have to use 'print', simply parentheses, in double quotation
you have to write your text, or message,
or string, whatever you want to print through your Python
program. That's it.
So 'print', parentheses,
then inside parentheses with quotations you have to write
some string or message or text.
Right. Now, let me save this.
First observe your script, whatever you have.
So this is our script, right?
So this is like in Windows 'cat' command, right?
I am seeing my file, my program, my script.
Yes, this is the line in my program.
Okay. So now I am going to run it 'python',
so guys if you want to run your script Python Script, you have
to run in this way on your Windows operating systems, 'python ',
your program name. But before going to that check it
whether you configured your Python on your host or not.
Yes, I am getting some version, means
I have a Python on my host,
and that version is some 3.7.0.
Now I can use 'python
hello_word.py'
See the output. You're getting 'Hello World!'.
[no audio]
Right. See guys, here
you have to understand one more thing, while running you are
running in this way 'python hello_word.py',
some program name, '.py'. Now as of now, I am using
Python 3, right.
So if I want to run same program with Python 3, so already
I have somewhere in my host Python 2 as well.
Right. Let me run with Python 2.
[no audio]
So you have to provide complete path because you can't add
two paths to your system paths,
that's why I am selecting Python 3 as the default one, and
for Python 2 whenever if I want to run my Python Script
with Python 2 I will provide the complete path for my
Python 2 version.
So my Python 2 is there in this location. If you want to check
you can check 'version'.
Right. Now if you want to run your script using Python 2
just provide complete path where you installed your Python,
then your program name, or script name. See that?
[no audio]
That's it.
Okay. And guys whatever we've written, right, that script
we are running from command line.
So this is the first thing you have to know, because as an
automation engineer you how to run your scripts from command
line. We already discussed this point.
Fine. So guys if you want to write one more line, so I want
to print output like "Hello World!" or "Welcome to Python",
so this is in one line.
I want to print one more line. Then 'print', in quotations whatever
you want to print you just write that information here.
So I am writing,
"Welcome to Python Scripting".
If you want to write one more line, let's say 'print(
"This is my first script").
So now through our Python Script
we are printing three lines of information with the help
of this script.
Let me save it, and observe the output.
I mean first observe your script, now run it,
[no audio]
'Enter'. See
the output. Whatever you have inside of your 'print', inside
of your quotations,
that information is printing.
And guys whenever if you run your Python program, it will
run from top to bottom, line by line, right. Very first line
"Hello World!", first
this information will be printed, then this one, then this one.
Right. So this is a simple script with your Python and here we've written
our script with the help of 'vim', and we are running that
with Python 3 as well as Python 2 also, right.
So guys if you are having confusion like running simply by
'python', or by providing complete 'python' path, right,
just try to install only one Python on your host, and set
the path for your Python, and just try to work with that only.
Right. In case if you have both the Python versions on your
host just provide your, just add your 'python' path to your
system path for only anyone of the Python versions, it maybe 2 or 3,
right, and come to command line, and just type in this way.
suppose here if you are getting 3.7.0 then by default you're running
your Python programs with the help of Python 3 version.
So if you want to run this program with any other version
just try to provide complete path of your Python Interpreter.
That is nothing but 'python.exe'.
Of course, no need to provide '.exe', by default
it will take '.exe' extension because you are on your
Windows operating system.
That's it.
Okay. And here guys, I need to provide one more clarity. Observe
that in your script, right,
this entire thing is a string or text or message, right?
Actually, this is a string. If you want to print any string on your
command line while running your program always you have to
take a 'print'. See here,
this is a number, right? Number is also a string if you provide
inside of your quotation.
String is nothing but group of characters.
If you write anything inside of quotations, that will be
a string, that is always a string. If you write anything inside
of quotations that is always a string.
So 'print' is used to simply to print some string on your command
line, on your terminal, on your display while running your
program, while running your script.
Right. Fine. So till now we worked with
'vim' editor from command line.
We know once if we install your Python, right, by default
you will get 'IDLE'. Let me click this 'IDLE'.
Right. Let me open that 'IDLE'.
[no audio]
It's opening.
Yeah, it's done. Right. Now,
you can go with the 'File', and 'New', and whatever the program
you have, whatever the script you have just copy and paste
it or you can type it, and save it.
[no audio]
Okay. You can save it anywhere, right, otherwise go with 'File',
and 'Open' your existing Python program.
So already we have on our Desktop somewhere here
we have some 'hello_word'.
Now this is the program, right. Now,
let me close this.
Now this is your script, so you can run this from here also.
See the output you're going to get.
So guys, you can also write your Python scripts or programs
by using IDLE also. So for that what you have to do? Just
to go to your 'Start', and then click on 'IDLE'. It will open
this 'IDLE', right, Python Shell. Click on 'File->New' in case
if you want write a new Python program, or if you have some
existing Python just click on 'Open' and select your Python
program from your particular location.
Then it will open like this, then go and run here using 'Run'
module, or from your keyboard
you can also click on 'F5' so that your program will run.
[no audio]
So guys my suggestion is, just try to know about IDLE, but
don't use this 'IDLE'. If you want to use you can use it.
But my preference is command line 'vim' editor,
or 'vi' editor on your Unix-like systems.
'vi' or 'vim', that's it. You can take anything.
Okay. So guys, this is the simple way to write simply
"Hello World!", or any to print some message with the help of your
Python. Okay.
Okay guys. Thank you for watching this video.
[no audio]