1 00:00:00,150 --> 00:00:03,300 Print function the print function. 2 00:00:03,300 --> 00:00:07,770 Print a specified message to the screen. 3 00:00:07,890 --> 00:00:11,360 Or any other standard output device. 4 00:00:11,490 --> 00:00:17,590 And this message can be a string or any other object. 5 00:00:17,610 --> 00:00:27,240 This is the syntax for the print function the print function can print an arbitrary number of values 6 00:00:27,540 --> 00:00:29,870 separated by commas. 7 00:00:29,940 --> 00:00:41,840 So while you 1 value 2 when 2 3 and so on I have assigned the value to 2 to this variable X and using 8 00:00:41,840 --> 00:00:51,200 the print function I'm going to print the string X equal to the text but then these double quotes and 9 00:00:51,200 --> 00:01:01,920 then I have separated values the first value value 1 and the second while you value 2 with a comma. 10 00:01:01,920 --> 00:01:05,520 Let us see how this is going to be displayed. 11 00:01:06,910 --> 00:01:11,400 On this screen so x equal to 2. 12 00:01:11,440 --> 00:01:13,480 This is how it got displayed 13 00:01:15,940 --> 00:01:16,990 next. 14 00:01:17,020 --> 00:01:23,020 I'm going to print two more strings here. 15 00:01:23,560 --> 00:01:35,340 So the first string is going to be X the second one is going to be white and in the syntax for the print 16 00:01:35,340 --> 00:01:36,390 function. 17 00:01:36,390 --> 00:01:41,310 We can also specify a separator as a B. 18 00:01:41,430 --> 00:01:54,140 The key word ACP which is the separator and by default it has one space and you can redefine the separator. 19 00:01:54,140 --> 00:02:01,380 Let's say we do not want any spaces between the values X and then white. 20 00:02:01,400 --> 00:02:04,520 So let's change the separator. 21 00:02:04,520 --> 00:02:06,510 I'm going to delete this space. 22 00:02:06,620 --> 00:02:09,550 Let's execute this cell. 23 00:02:10,010 --> 00:02:16,650 So as you can see the space between X and Y has been removed. 24 00:02:16,690 --> 00:02:20,480 Now let's have another separator. 25 00:02:20,500 --> 00:02:26,730 We have two values the String x and the string. 26 00:02:26,730 --> 00:02:30,940 Why are the values the separator. 27 00:02:30,940 --> 00:02:37,470 In this case let's say it is a colon and then execute. 28 00:02:37,540 --> 00:02:48,940 We have the colon as a separator between the values defined in the print function I have used a for 29 00:02:48,940 --> 00:03:00,240 loop to retrieve each of the characters in the string python and after the training say for example 30 00:03:00,240 --> 00:03:09,540 the first character I'm using the print function to print the character be next do for loop retrieves 31 00:03:09,870 --> 00:03:20,400 the second character y and using the print function it prints out the character y in the output similarly 32 00:03:20,400 --> 00:03:31,830 it prints all of the characters in the string Python as you can see a print call is ended by a new line 33 00:03:33,370 --> 00:03:35,930 and we can change this behavior. 34 00:03:36,310 --> 00:03:46,680 So for example we can assign an arbitrary string to the keyboard parameter in say for example let's 35 00:03:47,070 --> 00:03:58,260 use the for loop again in order to access the characters in the string python and then using the print 36 00:03:58,260 --> 00:03:59,020 function. 37 00:03:59,040 --> 00:04:11,820 I'm going to print devalue I so let's print I and the the parameter and this time is now defined to 38 00:04:11,820 --> 00:04:16,380 be a single space let's execute this. 39 00:04:16,380 --> 00:04:26,900 So as you can see instead of printing each character in a new line since we have redefined the parameter 40 00:04:26,990 --> 00:04:38,350 and with space here a single space a space has been included between each of the characters. 41 00:04:38,350 --> 00:04:40,600 This is not a separator here. 42 00:04:40,840 --> 00:04:50,550 It is the space in this case in numbered example is end of the line. 43 00:04:50,590 --> 00:04:58,780 Until now we have talked about parameter separated and the end parameter. 44 00:04:58,780 --> 00:05:04,900 Next we will talk about this parameter file in computer programming. 45 00:05:04,930 --> 00:05:14,820 If a computer program wants to communicate with its environment program that is getting executed wants 46 00:05:14,820 --> 00:05:17,760 to communicate the output to it. 47 00:05:17,790 --> 00:05:26,280 In my admin there are p connected input and output communication channels between the computer program 48 00:05:26,490 --> 00:05:28,320 and the environment. 49 00:05:28,320 --> 00:05:35,280 Also known as standard streams and there are three input output connections. 50 00:05:35,280 --> 00:05:45,690 The first one is the standard input and this is the D5 place read the program listens for information 51 00:05:45,930 --> 00:05:58,690 or input and this could be input from your keyboard next is the standard output the standard output 52 00:05:58,690 --> 00:06:02,530 is the default place for the output to go. 53 00:06:02,590 --> 00:06:11,590 So when you use the print function to bring a string or some value it goes to these standard output 54 00:06:13,180 --> 00:06:19,010 next is the standard error stream. 55 00:06:19,420 --> 00:06:27,730 And just like the standard output and standard input this is the place where error messages go 56 00:06:30,570 --> 00:06:49,650 and standard input is also call is D I N standard output is d d out or UTI standard error is is d d 57 00:06:49,890 --> 00:07:03,520 e at just like you send your output messages from a piece of code to the screen that does your computer 58 00:07:03,520 --> 00:07:13,030 monitor you can also send this text to a file so in that case you do not see the output on your screen. 59 00:07:13,510 --> 00:07:21,750 But this can be seen in a file and let us see how this can be done using the print function. 60 00:07:21,910 --> 00:07:35,290 The print function has this parameter file and by default says DOT is Judy out which is the terminal 61 00:07:35,320 --> 00:07:37,680 or the window in which we are working. 62 00:07:37,770 --> 00:07:47,340 If you want to send the values from the print function into a file that can be done by changing this 63 00:07:47,610 --> 00:08:01,260 parameter so let's discuss about this by default the file parameter is as didi out which means your 64 00:08:01,350 --> 00:08:06,950 output goes to the computer screen and this can be changed. 65 00:08:07,080 --> 00:08:12,750 Say for example you can output the content of a program to a file. 66 00:08:13,140 --> 00:08:14,740 So let's see this. 67 00:08:14,760 --> 00:08:20,420 So here I have created a file object. 68 00:08:20,520 --> 00:08:32,640 If using the open function the built in function open and this is file that I'm going to create print 69 00:08:32,640 --> 00:08:39,480 function dot the X T and I'm opening this in the access mode w. 70 00:08:39,970 --> 00:08:45,580 Now I want to create defined and using the print function. 71 00:08:45,580 --> 00:08:49,250 I want to write this text into this file. 72 00:08:49,420 --> 00:08:54,130 If that is print function dot DST. 73 00:08:54,220 --> 00:08:59,920 And finally after writing the text I'm going to close the file using the close method. 74 00:09:00,700 --> 00:09:03,060 So let's execute this. 75 00:09:04,050 --> 00:09:12,300 So as you can see nothing has been displayed using the print function. 76 00:09:12,300 --> 00:09:19,490 That's because the file parameter is not as Judy's out which is the standard output anymore. 77 00:09:19,500 --> 00:09:22,560 It is now a text file. 78 00:09:23,520 --> 00:09:32,220 So let's open this file print function that the x d text file print function 30 60 and using the print 79 00:09:32,220 --> 00:09:32,970 function. 80 00:09:32,970 --> 00:09:41,650 This is what we have entered into defined the last parameter is this flash. 81 00:09:42,120 --> 00:09:45,330 Which by default is false. 82 00:09:45,390 --> 00:09:52,910 So when you output to a stream from your program it does not go immediately to a file on the terminal 83 00:09:52,940 --> 00:09:53,860 window. 84 00:09:53,940 --> 00:10:02,040 It will be put into a buffer that it will be held until there is enough data to be what outputting for 85 00:10:02,040 --> 00:10:11,550 example a full block to file on disk flushing the output stream forces all output to be written out 86 00:10:12,120 --> 00:10:16,640 so that it is in a disk file or appears on the screen. 87 00:10:16,920 --> 00:10:23,040 And this is occasionally what is needed but it should not be done if it is not needed. 88 00:10:23,670 --> 00:10:31,650 And if you assign the Boolean value true to flush it might slow a program down.