Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I. A string that spans multiple lines If you want to define a string that spans multiple lines, you should use triple quotes. For example:

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
I. A string that spans multiple lines If you want to define a string that spans multiple lines, you should use triple quotes. For example: s = ""My address is 2200 Campbell st. Commerce, TX 75428 print (s) II. Special symbols in a string If you want to type special symbols in a string, you should use some tricks. If we want to have a string that includes" or ", we can use the other quote. For example: sl - "It's okay." print (1) 32 = 'My brother calls me "Batman". print (2) What if we have a string that includes both " and "? We can use. For example: print("John Rambo is 5'11" tall.") - 2 x A A : T Normal 1 No Spac... Heading 1 Heading 2 Title s Paragraph Styles s1 = "It's okay." print (1) 82 = 'My brother calls me "Batman". print (s2) What if we have a string that includes both' and "? We can use \. For example: print("John Rambo is 5'11" tall." In fact, is used to indicate a special symbol in a string, including: Notation, Symbol Notation Symbol Tab New line Return Backspace Null Backslash Since is used to indicate a special symbol, is used to indicate a normal backslash itself. III. Multiple assignment In Python, it is possible to assign multiple values to multiple variables in one statement. For example: a, b, c = , 3.2, "Hello" print (a print (b) Focus Normal No Space Heading 1 Heading 2 Title Sub Font Paragraph Styles III. Multiple assignment In Python, it is possible to assign multiple values to multiple variables in one statement. For example: a, b, c = 5, 3.2, "Hello" print (a) print (b) print (c) "same x = y = Z print (x) print (y) print (2) IV. Formatting the output Focus Courier New 12 MA A Aa A BI b * *' AA 4 AaBbcci AaBbcel AaBbc AaBbce AaB PELIT Normal 1 No Spac... Heading 1 Heading 2 Title Paragraph Font Styles Let's look at a sample program: toy price = 10.99 quantity = 3 tax rate = 0.08 total tax - toy...price. quantity tax rate total price - toy price* quantity + total tax print("The total price of", quantity, "toys is", total price) The output is The total price of 3 toys is 35.6076 However, how can we pay for $0.0076? Then there is an alternative way to display the number: print("The total price of", quantity, "toys is 6.25" (total price)) Here is the modulo operator for string. 4.2f indicates that the print function only displays two digits after the decimal. However, there are two things you need to pay attention to: (1) This does not change the value of the data. It only affects the screen display. The value of total price is still 35.6076. (2) The syntax is not the same. After the closing quote, you should type another instead of a comma, and put the data in the following parenthesis. Fo If we want to adjust the alignment of the string, we can use center(), ljust(), or just(). For example: m = "What is the time?" print (m) print (m.center (25, "*")) print (m.liust (25, "*")) print (m.rjust (30," ")) print (m) The above code will generate the following output: What is the time? hat is the time? ### What is the time 2** Focus I. A string that spans multiple lines If you want to define a string that spans multiple lines, you should use triple quotes. For example: s = ""My address is 2200 Campbell st. Commerce, TX 75428 print (s) II. Special symbols in a string If you want to type special symbols in a string, you should use some tricks. If we want to have a string that includes" or ", we can use the other quote. For example: sl - "It's okay." print (1) 32 = 'My brother calls me "Batman". print (2) What if we have a string that includes both " and "? We can use. For example: print("John Rambo is 5'11" tall.") - 2 x A A : T Normal 1 No Spac... Heading 1 Heading 2 Title s Paragraph Styles s1 = "It's okay." print (1) 82 = 'My brother calls me "Batman". print (s2) What if we have a string that includes both' and "? We can use \. For example: print("John Rambo is 5'11" tall." In fact, is used to indicate a special symbol in a string, including: Notation, Symbol Notation Symbol Tab New line Return Backspace Null Backslash Since is used to indicate a special symbol, is used to indicate a normal backslash itself. III. Multiple assignment In Python, it is possible to assign multiple values to multiple variables in one statement. For example: a, b, c = , 3.2, "Hello" print (a print (b) Focus Normal No Space Heading 1 Heading 2 Title Sub Font Paragraph Styles III. Multiple assignment In Python, it is possible to assign multiple values to multiple variables in one statement. For example: a, b, c = 5, 3.2, "Hello" print (a) print (b) print (c) "same x = y = Z print (x) print (y) print (2) IV. Formatting the output Focus Courier New 12 MA A Aa A BI b * *' AA 4 AaBbcci AaBbcel AaBbc AaBbce AaB PELIT Normal 1 No Spac... Heading 1 Heading 2 Title Paragraph Font Styles Let's look at a sample program: toy price = 10.99 quantity = 3 tax rate = 0.08 total tax - toy...price. quantity tax rate total price - toy price* quantity + total tax print("The total price of", quantity, "toys is", total price) The output is The total price of 3 toys is 35.6076 However, how can we pay for $0.0076? Then there is an alternative way to display the number: print("The total price of", quantity, "toys is 6.25" (total price)) Here is the modulo operator for string. 4.2f indicates that the print function only displays two digits after the decimal. However, there are two things you need to pay attention to: (1) This does not change the value of the data. It only affects the screen display. The value of total price is still 35.6076. (2) The syntax is not the same. After the closing quote, you should type another instead of a comma, and put the data in the following parenthesis. Fo If we want to adjust the alignment of the string, we can use center(), ljust(), or just(). For example: m = "What is the time?" print (m) print (m.center (25, "*")) print (m.liust (25, "*")) print (m.rjust (30," ")) print (m) The above code will generate the following output: What is the time? hat is the time? ### What is the time 2** Focus

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions