1 00:00:00,000 --> 00:00:02,300 [no audio] 2 00:00:02,309 --> 00:00:03,900 Hi friends, here 3 00:00:03,900 --> 00:00:07,300 we are going to write very simple Python Script, and that 4 00:00:07,300 --> 00:00:09,500 is simply printing some message. 5 00:00:10,500 --> 00:00:13,300 So here I am going to print "Hello World!" 6 00:00:14,400 --> 00:00:18,100 using your Python Script, and what about the script you are 7 00:00:18,100 --> 00:00:24,400 going to write? That I am going to write using 'vim', and 'Default IDLE'. 8 00:00:24,400 --> 00:00:28,600 So here we are going to see a simple Python Script 9 00:00:28,800 --> 00:00:33,600 by using either 'vim' editor, or 'Default IDLE', right. 10 00:00:33,800 --> 00:00:35,000 Let me open first of all 11 00:00:35,000 --> 00:00:38,000 my command line on my Windows operating system. 12 00:00:38,100 --> 00:00:41,500 You can write same program, same script on your Linux or any 13 00:00:41,500 --> 00:00:43,700 Unix-like systems as well, right? 14 00:00:43,700 --> 00:00:46,500 So guys I'm moving into my desktop, there 15 00:00:46,500 --> 00:00:50,100 I am going to create 'PythonScripts' directory. 16 00:00:50,700 --> 00:00:53,500 Let me enter into that. See as of now 17 00:00:53,500 --> 00:00:55,000 you don't have anything in this directory. 18 00:00:56,300 --> 00:00:59,500 Right. See if you want to use 'vim' editor, 19 00:00:59,500 --> 00:01:02,700 first of all you should have 'vim' on your host. 20 00:01:03,200 --> 00:01:06,700 So in our previous video we have seen different types of 21 00:01:06,700 --> 00:01:10,500 editors, and I have given a link to install 'vim' editor on your 22 00:01:10,500 --> 00:01:11,800 Windows operating system. 23 00:01:11,800 --> 00:01:14,600 Anyway by default 'vi' is there on your Unix-like systems. 24 00:01:14,600 --> 00:01:18,100 You can use 'vi' on your Unix-like systems. But in Windows 25 00:01:19,200 --> 00:01:22,400 you don't have 'vi', but you can install 'vim', right? 26 00:01:22,500 --> 00:01:24,500 So I already installed that. Now 27 00:01:24,500 --> 00:01:31,100 let me run 'vim', simply 'hello_word.py'. You can take any 28 00:01:31,100 --> 00:01:35,800 name guys, any script name you can take, and extension is '.py' 29 00:01:35,800 --> 00:01:39,500 just to know that that is a Python Script or Python program. 30 00:01:40,200 --> 00:01:44,100 Now, let me enter 'vim ', some program name '.py'. 31 00:01:45,700 --> 00:01:49,900 Right. Now I am going to open your 'vim' editor. 32 00:01:50,400 --> 00:01:57,100 I opened that, right. See guys my intention is I have to write a 33 00:01:57,100 --> 00:02:02,200 some Python Script or Python program, and if I run that program 34 00:02:03,000 --> 00:02:06,700 I have to get output as simply some "Hello World!", right. 35 00:02:07,200 --> 00:02:10,600 So to print the something, to print some text or message or 36 00:02:10,600 --> 00:02:12,400 string in your Python 37 00:02:12,400 --> 00:02:17,700 you have to use 'print', simply parentheses, in double quotation 38 00:02:17,900 --> 00:02:20,300 you have to write your text, or message, 39 00:02:21,600 --> 00:02:24,200 or string, whatever you want to print through your Python 40 00:02:24,200 --> 00:02:25,900 program. That's it. 41 00:02:26,500 --> 00:02:28,400 So 'print', parentheses, 42 00:02:29,800 --> 00:02:33,100 then inside parentheses with quotations you have to write 43 00:02:33,100 --> 00:02:35,300 some string or message or text. 44 00:02:36,500 --> 00:02:38,700 Right. Now, let me save this. 45 00:02:40,300 --> 00:02:43,200 First observe your script, whatever you have. 46 00:02:43,400 --> 00:02:45,800 So this is our script, right? 47 00:02:46,100 --> 00:02:48,900 So this is like in Windows 'cat' command, right? 48 00:02:48,900 --> 00:02:51,600 I am seeing my file, my program, my script. 49 00:02:51,800 --> 00:02:54,500 Yes, this is the line in my program. 50 00:02:55,400 --> 00:02:58,900 Okay. So now I am going to run it 'python', 51 00:02:59,100 --> 00:03:02,500 so guys if you want to run your script Python Script, you have 52 00:03:02,500 --> 00:03:06,500 to run in this way on your Windows operating systems, 'python ', 53 00:03:06,500 --> 00:03:10,200 your program name. But before going to that check it 54 00:03:10,200 --> 00:03:13,200 whether you configured your Python on your host or not. 55 00:03:13,900 --> 00:03:15,700 Yes, I am getting some version, means 56 00:03:16,400 --> 00:03:17,900 I have a Python on my host, 57 00:03:18,000 --> 00:03:20,000 and that version is some 3.7.0. 58 00:03:20,600 --> 00:03:23,300 Now I can use 'python 59 00:03:24,600 --> 00:03:26,800 hello_word.py' 60 00:03:28,300 --> 00:03:29,800 See the output. You're getting 'Hello World!'. 61 00:03:29,800 --> 00:03:32,600 [no audio] 62 00:03:32,600 --> 00:03:35,000 Right. See guys, here 63 00:03:35,000 --> 00:03:37,800 you have to understand one more thing, while running you are 64 00:03:38,000 --> 00:03:40,900 running in this way 'python hello_word.py', 65 00:03:41,700 --> 00:03:46,000 some program name, '.py'. Now as of now, I am using 66 00:03:46,000 --> 00:03:47,900 Python 3, right. 67 00:03:48,300 --> 00:03:51,700 So if I want to run same program with Python 3, so already 68 00:03:51,800 --> 00:03:54,700 I have somewhere in my host Python 2 as well. 69 00:03:55,800 --> 00:03:57,500 Right. Let me run with Python 2. 70 00:03:57,500 --> 00:03:59,500 [no audio] 71 00:03:59,500 --> 00:04:02,000 So you have to provide complete path because you can't add 72 00:04:02,000 --> 00:04:04,000 two paths to your system paths, 73 00:04:04,000 --> 00:04:07,900 that's why I am selecting Python 3 as the default one, and 74 00:04:07,900 --> 00:04:11,200 for Python 2 whenever if I want to run my Python Script 75 00:04:11,200 --> 00:04:15,000 with Python 2 I will provide the complete path for my 76 00:04:15,000 --> 00:04:16,100 Python 2 version. 77 00:04:16,800 --> 00:04:19,399 So my Python 2 is there in this location. If you want to check 78 00:04:19,399 --> 00:04:20,600 you can check 'version'. 79 00:04:21,800 --> 00:04:25,899 Right. Now if you want to run your script using Python 2 80 00:04:26,600 --> 00:04:29,500 just provide complete path where you installed your Python, 81 00:04:29,900 --> 00:04:32,100 then your program name, or script name. See that? 82 00:04:32,100 --> 00:04:34,400 [no audio] 83 00:04:34,400 --> 00:04:35,400 That's it. 84 00:04:36,500 --> 00:04:42,100 Okay. And guys whatever we've written, right, that script 85 00:04:42,100 --> 00:04:43,700 we are running from command line. 86 00:04:44,400 --> 00:04:47,500 So this is the first thing you have to know, because as an 87 00:04:47,500 --> 00:04:51,400 automation engineer you how to run your scripts from command 88 00:04:51,400 --> 00:04:53,500 line. We already discussed this point. 89 00:04:54,500 --> 00:04:58,900 Fine. So guys if you want to write one more line, so I want 90 00:04:58,900 --> 00:05:03,100 to print output like "Hello World!" or "Welcome to Python", 91 00:05:04,600 --> 00:05:05,900 so this is in one line. 92 00:05:06,100 --> 00:05:10,600 I want to print one more line. Then 'print', in quotations whatever 93 00:05:10,600 --> 00:05:12,800 you want to print you just write that information here. 94 00:05:13,400 --> 00:05:14,400 So I am writing, 95 00:05:16,100 --> 00:05:18,300 "Welcome to Python Scripting". 96 00:05:19,500 --> 00:05:22,500 If you want to write one more line, let's say 'print( 97 00:05:23,600 --> 00:05:27,400 "This is my first script"). 98 00:05:28,400 --> 00:05:30,800 So now through our Python Script 99 00:05:30,800 --> 00:05:34,100 we are printing three lines of information with the help 100 00:05:34,100 --> 00:05:35,100 of this script. 101 00:05:35,400 --> 00:05:38,600 Let me save it, and observe the output. 102 00:05:38,600 --> 00:05:42,500 I mean first observe your script, now run it, 103 00:05:42,500 --> 00:05:45,500 [no audio] 104 00:05:45,500 --> 00:05:46,500 'Enter'. See 105 00:05:46,500 --> 00:05:51,200 the output. Whatever you have inside of your 'print', inside 106 00:05:51,200 --> 00:05:52,300 of your quotations, 107 00:05:52,300 --> 00:05:53,700 that information is printing. 108 00:05:55,100 --> 00:05:57,900 And guys whenever if you run your Python program, it will 109 00:05:57,900 --> 00:06:02,900 run from top to bottom, line by line, right. Very first line 110 00:06:02,900 --> 00:06:03,700 "Hello World!", first 111 00:06:03,700 --> 00:06:06,700 this information will be printed, then this one, then this one. 112 00:06:08,200 --> 00:06:14,200 Right. So this is a simple script with your Python and here we've written 113 00:06:14,200 --> 00:06:16,700 our script with the help of 'vim', and we are running that 114 00:06:16,700 --> 00:06:21,800 with Python 3 as well as Python 2 also, right. 115 00:06:22,700 --> 00:06:26,000 So guys if you are having confusion like running simply by 116 00:06:26,000 --> 00:06:29,900 'python', or by providing complete 'python' path, right, 117 00:06:29,900 --> 00:06:32,800 just try to install only one Python on your host, and set 118 00:06:32,800 --> 00:06:36,000 the path for your Python, and just try to work with that only. 119 00:06:39,200 --> 00:06:41,800 Right. In case if you have both the Python versions on your 120 00:06:41,800 --> 00:06:47,200 host just provide your, just add your 'python' path to your 121 00:06:47,200 --> 00:06:51,000 system path for only anyone of the Python versions, it maybe 2 or 3, 122 00:06:52,400 --> 00:06:55,900 right, and come to command line, and just type in this way. 123 00:06:56,500 --> 00:07:00,900 suppose here if you are getting 3.7.0 then by default you're running 124 00:07:00,900 --> 00:07:03,800 your Python programs with the help of Python 3 version. 125 00:07:05,200 --> 00:07:07,900 So if you want to run this program with any other version 126 00:07:08,000 --> 00:07:11,200 just try to provide complete path of your Python Interpreter. 127 00:07:11,600 --> 00:07:13,400 That is nothing but 'python.exe'. 128 00:07:14,000 --> 00:07:16,200 Of course, no need to provide '.exe', by default 129 00:07:16,200 --> 00:07:19,400 it will take '.exe' extension because you are on your 130 00:07:19,400 --> 00:07:20,500 Windows operating system. 131 00:07:22,000 --> 00:07:23,000 That's it. 132 00:07:24,000 --> 00:07:28,300 Okay. And here guys, I need to provide one more clarity. Observe 133 00:07:28,300 --> 00:07:29,900 that in your script, right, 134 00:07:31,600 --> 00:07:36,100 this entire thing is a string or text or message, right? 135 00:07:36,200 --> 00:07:39,900 Actually, this is a string. If you want to print any string on your 136 00:07:39,900 --> 00:07:42,900 command line while running your program always you have to 137 00:07:42,900 --> 00:07:44,800 take a 'print'. See here, 138 00:07:44,800 --> 00:07:48,300 this is a number, right? Number is also a string if you provide 139 00:07:48,300 --> 00:07:49,600 inside of your quotation. 140 00:07:50,700 --> 00:07:52,800 String is nothing but group of characters. 141 00:07:53,700 --> 00:07:57,000 If you write anything inside of quotations, that will be 142 00:07:57,000 --> 00:08:01,200 a string, that is always a string. If you write anything inside 143 00:08:01,200 --> 00:08:02,900 of quotations that is always a string. 144 00:08:03,400 --> 00:08:06,800 So 'print' is used to simply to print some string on your command 145 00:08:06,800 --> 00:08:10,300 line, on your terminal, on your display while running your 146 00:08:10,300 --> 00:08:12,500 program, while running your script. 147 00:08:13,600 --> 00:08:17,500 Right. Fine. So till now we worked with 148 00:08:17,500 --> 00:08:19,500 'vim' editor from command line. 149 00:08:20,000 --> 00:08:24,500 We know once if we install your Python, right, by default 150 00:08:24,500 --> 00:08:28,100 you will get 'IDLE'. Let me click this 'IDLE'. 151 00:08:30,700 --> 00:08:32,500 Right. Let me open that 'IDLE'. 152 00:08:32,500 --> 00:08:42,700 [no audio] 153 00:08:42,700 --> 00:08:43,700 It's opening. 154 00:08:43,900 --> 00:08:47,100 Yeah, it's done. Right. Now, 155 00:08:47,100 --> 00:08:52,799 you can go with the 'File', and 'New', and whatever the program 156 00:08:52,799 --> 00:08:55,400 you have, whatever the script you have just copy and paste 157 00:08:55,400 --> 00:08:58,000 it or you can type it, and save it. 158 00:08:58,000 --> 00:09:00,400 [no audio] 159 00:09:00,400 --> 00:09:06,100 Okay. You can save it anywhere, right, otherwise go with 'File', 160 00:09:06,500 --> 00:09:08,800 and 'Open' your existing Python program. 161 00:09:08,900 --> 00:09:12,600 So already we have on our Desktop somewhere here 162 00:09:12,600 --> 00:09:14,000 we have some 'hello_word'. 163 00:09:15,100 --> 00:09:17,900 Now this is the program, right. Now, 164 00:09:17,900 --> 00:09:19,000 let me close this. 165 00:09:20,500 --> 00:09:25,700 Now this is your script, so you can run this from here also. 166 00:09:26,800 --> 00:09:28,100 See the output you're going to get. 167 00:09:29,600 --> 00:09:33,000 So guys, you can also write your Python scripts or programs 168 00:09:33,000 --> 00:09:36,800 by using IDLE also. So for that what you have to do? Just 169 00:09:36,800 --> 00:09:41,800 to go to your 'Start', and then click on 'IDLE'. It will open 170 00:09:41,800 --> 00:09:47,800 this 'IDLE', right, Python Shell. Click on 'File->New' in case 171 00:09:47,800 --> 00:09:50,600 if you want write a new Python program, or if you have some 172 00:09:50,600 --> 00:09:56,000 existing Python just click on 'Open' and select your Python 173 00:09:56,000 --> 00:09:57,800 program from your particular location. 174 00:09:58,000 --> 00:10:02,000 Then it will open like this, then go and run here using 'Run' 175 00:10:02,000 --> 00:10:03,500 module, or from your keyboard 176 00:10:03,500 --> 00:10:08,000 you can also click on 'F5' so that your program will run. 177 00:10:08,000 --> 00:10:11,100 [no audio] 178 00:10:11,100 --> 00:10:15,000 So guys my suggestion is, just try to know about IDLE, but 179 00:10:16,100 --> 00:10:18,700 don't use this 'IDLE'. If you want to use you can use it. 180 00:10:18,700 --> 00:10:22,900 But my preference is command line 'vim' editor, 181 00:10:23,000 --> 00:10:25,200 or 'vi' editor on your Unix-like systems. 182 00:10:25,200 --> 00:10:27,300 'vi' or 'vim', that's it. You can take anything. 183 00:10:28,700 --> 00:10:33,100 Okay. So guys, this is the simple way to write simply 184 00:10:33,100 --> 00:10:35,900 "Hello World!", or any to print some message with the help of your 185 00:10:35,900 --> 00:10:37,500 Python. Okay. 186 00:10:38,100 --> 00:10:40,100 Okay guys. Thank you for watching this video. 187 00:10:40,100 --> 00:10:49,100 [no audio]