![python double quotes terminal python double quotes terminal](https://pennbookcenter.com/wp-content/uploads/2021/07/Python-Single-Vs-Double-Quotes.jpg)
![python double quotes terminal python double quotes terminal](https://i.ytimg.com/vi/mKfgVKLI9T8/maxresdefault.jpg)
Listing 4.3 Protecting a Single Quote with Double Quotes > print("This example protects the output's single quote.") In such a case, you should use double quotes around the print function argument, as shown in Listing 4.3. Sometimes you need to output a character string that contains a single quote mark to show possession or a contraction. Mixing your quotation marks back and forth makes the code harder for humans to read. Even though Python doesn’t care, it is considered poor form to use single quotes on one print function argument and then double quotes on the next. If you prefer double quotation marks, then consistently use them. If you like to use single quotation marks to enclose string literals in a print function argument, then consistently use them. This is an example of using double quotes.īy the Way: Choose One Type of Quotes and Stick with It Listing 4.2 Using a Pair of Double Quotes to Enclose Characters > print("This is an example of using double quotes.") You can see that the resulting output in both Listing 4.1 and Listing 4.2 does not contain the quotation marks, only the characters. Listing 4.2 shows the use of double quotes with the print function. This is an example of using single quotes. Listing 4.1 Using a Pair of Single Quotes to Enclose Characters > print('This is an example of using single 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. 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. Using Characters as print Function Arguments You learn about variables later in this hour. It also can be values stored in variables. The argument portion of the print function can be characters, such as ABC or 123. It is provided for your use when you install Python. You don’t need to do anything special to get this function. The print function is called a built-in function because it is part of the Python standard functions library. You simply enter a single Python statement to perform a task for you.ĭid You Know?: Standard Library of Functions Exploring the print FunctionĪ function is a group of Python statements that are put together as a unit to perform a specific task. The print function, which you met in Hour 3, “Setting Up a Programming Environment,” is a good place to focus your attention. You get instant feedback on your Python statements from the Python interactive interpreter and can experiment with proper syntax. Understanding how to produce output from a Python script is a good starting point for those who are new to the Python programming language. 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 You will read about using variables and how to assign values to variables, and you will gain an understanding of their data types. In this hour, you get a chance to learn some Python basics, such as using the print function to display output.