Article

Understanding Python Basics

Topic: Coach Training and CertificationPublished January 5, 2018
No ratings yet642 viewsSign in to rate

you will learn some Python basics, 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 this chapter, you will know how to get data into a script by using the input function and write your first Python script!
you get a chance to learn some Python basics, 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 Outputr
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, “Setting Up a Programming Environment,” is a good place to focus your attention at Infocampusr
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’s 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 Argumentsr
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, 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 pytho
3 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 (>>>), 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 Quotesr
In steps 8–10, you will not be completing the print function on one line. Instead, 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’s 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, 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, type print("Use escape sequences to
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, insert a linefeed., is on another line. This is due to your insertion of the escape sequence
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, 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.

Further reading

Further Reading

4 total

Article

How Coaching Turns Knowledge Into Change Walk into any bookstore or scroll through your favorite podcast feed, and you’ll see the same thing: endless tips, strategies, and “life hacks” promising transformation.rnWe devour them. We highlight paragraphs. We even try to practice what we’ve learned. But somehow, the big shifts never stick. Weeks later, the old patterns creep back in.rnSo why does it happen? Why do so many smart, motivated people keep getting stuck — eve

October 6, 2025

Article

grinding and cutting a variety of materials across numerous industries. Understanding their construction, types and safety precautions is mandatory for anyone working with these powerful tools. This article will explore the basics of abrasive wheels, offering insights into their components, maintenance and legal requirements to ensure both effective and safe usage. Exploring the Basics of Abrasive Wheels Abrasive wheels are critical tools in various industrial applications, f

March 6, 2025

Article

The internet we use daily, known as the surface web, represents only a fraction of the entire digital landscape. Beneath this visible layer lies the deep web and the dark web, where anonymity, privacy, and unrestricted information exchange thrive. Among the most well-known directories for accessing dark web content is the Uncensored Hidden Wiki . This article delves into the history, significance, risks, and access methods of the Uncensored Hidden Wiki, providing a comprehens

January 31, 2025

Article

If you're searching for exceptional piano classes near you, there are several excellent options in Toronto to consider. For those eager to learn the piano, finding a school or instructor that offers expert guidance, comprehensive lesson plans, and a supportive environment is key. Catering to both beginners and advanced players, many schools in the Toronto area provide tailored lessons to help students achieve their musical aspirations. What to Look for in Piano Lessons When

January 1, 2025