Python Mini Class: The ‘Talking’ Print Magic Assistant!

In the magical world of Python, there is an amazing “printing assistant”—the print function!

Introducing the Print Assistant

First, let’s take a look at a cartoon portrait of the print assistant! It has a round “head” called print, and a pair of magical “ears”. Just put the content you want to display into its “ears”, and it will immediately shout it out on the computer screen, just like broadcasting with a small loudspeaker.

Python Mini Class: The 'Talking' Print Magic Assistant!

Basic Magic: Let Print “Speak”

Magic 1: Print Text

Want the print assistant to say something you like? The secret is to dress the text in “English quotation marks” and then put it into its “ears”!

For example, input the code:

print("我是编程小高手!")print("冰淇淋真好吃~")

Little challenge: Let print say your name! For example, print (“我叫小明!”), go try it out!

Magic 2: Calculate Arithmetic

The print assistant is also a little math genius! When it encounters an arithmetic expression, there’s no need to dress it in “quotation marks”; just put it directly into its “ears”, and it can calculate the result!

See the example code:

print(2 + 3)print(10 - 4)print(5 × 6)print(8 ÷ 2)

Little challenge: Go try print(1000//5)

Advanced Magic: Let Print “Show” Off

Magic 1: Say Multiple Things at Once

Want print to say several sentences or solve several problems at the same time? Just separate the content with “English commas” and put it into its “ears”!

print("我的年龄是:", 8, "岁")print("3+2=", 3+2, "5-1=", 5-1)

Little task: Let print say your hobbies and the result of “20-8” at the same time!

Magic 2: Make Text “Dance” with Line Breaks

Want the text to change lines like queuing? Here’s a little “line break magic”—\n! Put it into the text, and print will automatically break the line when it sees it!

print("第一行文字\n第二行文字")print("苹果\n香蕉\n橘子")

High-Level Magic: Make Friends with Variables

Sometimes we store information in “variable boxes”, like names and ages, and print can easily read the content inside the box!

Method 1: Comma Separation Method

name = "小明"age = 12print("姓名:", name, "年龄:", age)

Method 2: f-string Magic (Recommended!)

Add an f before print, and wrap the variable in { }, and you can perfectly blend text and variables!

name = "小明"age = 12print(f"姓名:{name} 年龄:{age}")

Practical Case: Create a Personal Information Card

name = "小红"age = 13grade = 7score = 95.5print(f"=====学生信息卡=====")print(f"姓名:{name}")print(f"年龄:{age}岁")print(f"年级:{grade}年级")print(f"平均分:{score}分")print("====================")

Class Summary

  1. Print is Python’s “printing assistant” that can display text and arithmetic expressions.
  2. To display text, use English quotation marks; for arithmetic expressions, no quotation marks are needed.
  3. To display multiple contents at once, separate them with English commas.
  4. Use the “\n” magic for line breaks.
  5. When collaborating with variables, the f-string method is super useful!

Post-Class Exercises

  1. Basic question: Let print say “我爱编程”.
  2. Basic question: Let print calculate the result of “15+7”.
  3. Advanced question: Use one print to simultaneously display “今天天气真好!” and the result of “9×3”.
  4. Challenge question: Let print display “星期一” “星期二” “星期三” on separate lines.

Leave a Comment