you get a chance to learn some Python basics Cheap Jaromir Jagr Hat , such as using the print function to display output. You will read about using variables and how to assign values to variables, and you will gain an understanding of their data types. By the end of the hour, you will know how to get data into a script by using the input function and write your first Python script! Producing Python Script Output Understanding how to produce output from a Python script is a good starting point for those who are new to the Python programming language. You get instant feedback on your Python statements from the Python interactive interpreter and can experiment with proper syntax. The print function, which you met in Hour 3 Cheap Evgenii Dadonov Hat , 鈥淪etting Up a Programming Environment,鈥?is a good place to focus your attention at Infocampus Exploring the print Function A function is a group of Python statements that are put together as a unit to perform a specific task. The print function鈥檚 task is to output items. The items to output are correctly called an argument. The argument portion of the print function can be characters, such as ABC or 123. It also can be values stored in variables. Using Characters as print Function Arguments To display characters (also called string literals) using the print function, you need to enclose the characters in either a set of single quotes or double quotes. Listing 4.1 shows using a pair of single quotes to enclose characters (a sentence) so it can be used as a print function argument. Try It Yourself: Create Output with the print Function This hour you have been reading about creating and formatting output by using the print function. Now it is your turn to try this versatile Python tool. Follow these steps: 1. If you have not already done so Cheap Vincent Trocheck Hat , power up your Raspberry Pi and log in to the system. 2. If you do not have the GUI started automatically at boot, start it now by typing startx and pressing Enter. 3. Open a terminal by double-clicking the Terminal icon. 4. At the command-line prompt, type python3 and press Enter. You are taken to the Python interactive shell, where you can type Python statements and see immediate results. 5. At the Python interactive shell prompt (>>>) Cheap Aleksander Barkov Hat , type print('I learned about the print function.') and press Enter. 6. At the prompt, type print('I learned about single quotes.') and press Enter. 7. At the prompt, type print("Double quotes can also be used.") and press Enter. By the Way: Multiple Lines with Triple Double Quotes In steps 8鈥?0, you will not be completing the print function on one line. Instead Cheap Jared McCann Hoodie , you will be using triple double quotes to enable multiple lines to be entered and displayed. 8. At the prompt, type print("""I learned about things like... and press Enter. 9. Type triple quotes, and press Enter. 10. Type and displaying text on multiple lines.""") and press Enter. Notice that the Python interactive shell did not output the Python print statement鈥檚 argument until you had fully completed it with the closing parenthesis. 11. At the prompt, type print('Single quotes protect "double quotes" in output.') and press Enter. 12. At the prompt Cheap Jamie McGinn Hoodie , type print("Double quotes protect 'single quotes' in output.") and press Enter. 13. At the prompt, type print("A backslash protects \"double quotes\" in output.") and press Enter. 14. At the prompt, type print('A backslash protects \'single quotes\' in output.') and press Enter. Using the backslash to protect either single or double quotes enables you to maintain your chosen method of consistently using single (or double) quotes around your print function argument. 15. At the prompt, type print("The backslash character \\ is an escape character.") and press Enter. 16. At the prompt Cheap Radim Vrbata Hoodie , type print("Use escape sequences to \n insert a linefeed.") and press Enter. In the output, notice how part of the sentence, Use escape sequences to, is on one line and the end of the sentence Cheap James Reimer Hoodie , insert a linefeed., is on another line. This is due to your insertion of the escape sequence \n in the middle of the sentence. 17. At the prompt, type print("Use escape sequences to \t\t insert two tabs or" and press Enter. 18. At the . . . prompt, type "insert a check mark: \u2714") and press Enter. You can do a lot with the print function to display and format output! In fact Cheap Nick Bjugstad Hoodie , you could spend this entire hour just playing with output formatting. However, there are additional important Python basics you need to learn, such as formatting scripts for readability. More About the Author
We offer innovative and customized Java Training in Bangalore. Best Java course in Bangalore with Certified Experts. Go to free demo classes, get prepared by 8yrs experienced tutors and furthermore get hands on live project. Visit: Total Views: 53Word Count: 713See All articles From Author
Cup sleeves Internet Articles | December 19 Cheap Connor Brickley Hoodie , 2011 No matter which kind of drink you like to take but it would be attractive for you to take it with decent cutleries i.e. comfortable types of cups. A number of cups are found and used for serving the...