Python for Beginners: A Detailed Introduction to Python

Young people often fear programming difficulties; they want to learn Python but are hesitant, wavering through several springs.

In the world, difficulty and ease are always relative; it is easy if you try, but difficult if you do not. Let’s see how a poor monk goes to Hainan.

— Adapted from “Chou Nu Er”

In the early morning, the rising sun casts a golden light over Jinsuli Mountain. Although the mountain is not very high, it is lush with trees, stretching from west to east like a golden dragon. The westernmost peak rises abruptly, known by locals as the Dragon Head. To the east of the Dragon Head, dozens of peaks rise and fall, referred to as the Dragon Body by the locals. The easternmost peaks gradually lower in height, merging into the Jinsuli River, known as the Dragon Tail. With the golden dragon as a backdrop, the locals take pride in calling it the world’s number one feng shui treasure land. Although this may be an exaggeration, there is some basis for it: half of the eighteen emperors of the Tang Dynasty built their tombs here. Such density is unparalleled in history, and calling it the ‘number one feng shui treasure land’ is not an overstatement.

Setting this aside, let’s talk about the area below Jinsuli Mountain, where there is a county named Jinling County. This county has a long history, said to have had tribes living here since the time of Yao, and it was established as a county after the Qin unified the six states. Later, during the Tang Dynasty, the king repaired the tombs and named it Jinling, continuing to this day. To the north of Jinling County, there is a village called Jizhuang, with over a hundred households, most of whom have the surname Ji. In the west of the village, there is a household that lives against the mountain, making a living through farming and studying. The elderly couple is over fifty years old, and they have only one son, who was born at dawn, so they named him Ji Xiaoming. Locals pronounce ‘Xiao’ as ‘Xiao’, so many call him ‘Xiao Ming’, and thus ‘Xiao’ replaced ‘Xiao’.

Ji Xiaoming is just coming of age. He entered Scratch Academy at a young age and learned many skills over the years. Although Scratch is good, there are greater things beyond it, and Python is in its prime. It is said that if one learns programming without knowing Python, it is like walking in the dark at midnight. With a foundation in Scratch, learning Python should not be difficult. So he bid farewell to his teachers and friends, determined to go out and study.

Before he could set out, one day his father went up the mountain and unexpectedly encountered a rainstorm. In a hurry, he fell from a small cliff, fortunately without serious injury, but his left leg was fractured and would take time to heal. Xiaoming had to put aside his studies, spending each day seeking medical treatment and caring for his father, and in his spare time, he would go to the east of the village to seek advice from Xiao Hei.

Xiao Hei, however, is not a local of Jizhuang. He fled to Jizhuang during the Republic of China and later settled here. His surname is Du, and he was born at night when one could not see one’s hand in front of one’s face, so he was named ‘Heizi’. When he entered school, he disliked the name ‘Heizi’ for being unrefined, so he changed it to ‘Zihei’, and friends often call him ‘Xiao Hei’. Xiao Hei is two years older than Xiaoming and has been studying Python for a year, achieving considerable success.

When Xiaoming arrived, Xiao Hei was reading Li Bai’s “Quiet Night Thoughts”: “The bright moonlight before my bed, I suspect it is frost on the ground. I raise my head to gaze at the bright moon, and lower it to think of my hometown.” He was shaking his head and swaying, deeply immersed in it.

Upon learning Xiaoming’s intention, Xiao Hei said: “Since the advent of computers, programming has flourished. Over the past century, many programming schools have emerged, and the competition has been fierce. There are still over a hundred schools in existence today, but only a handful are truly powerful.”

Xiaoming asked, “What about Python?”

Xiao Hei replied: “Python has been around for thirty years. Compared to many schools, it is known for its simplicity, ease of use, and strong cross-platform capabilities, with many disciples and an extremely broad application market. If you learn Python, you will have no worries about finding a place to apply it.”

Xiaoming asked, “Where should I start learning Python?”

Xiao Hei said: “To do a good job, one must first sharpen their tools. To learn Python, you naturally need to install Python first. Since its inception, Python has undergone several iterations, and now it is in its third version. For Windows, Python 3.9 is a major watershed; from this version on, Python no longer supports Windows 7.”

Xiaoming replied: “That’s fine; my Windows has long been upgraded to Windows 10.”

He continued: “I have already installed Python on my computer; can I start learning now?”

Xiao Hei said: “Not yet. It’s like mathematics; knowledge is essential. When you learn mathematics, don’t you need textbooks? Textbooks are tools for learning mathematics. Python is similar; when learning it, you also need tools.”

Xiaoming asked: “Are you referring to PyCharm?”

Xiao Hei said: “Since you know PyCharm, it shows you have put in some effort. With this determination, why worry about not succeeding in learning Python! There are many tools available for learning Python, and PyCharm is one of the best among them. I also use PyCharm regularly.”

Xiaoming said: “Hearing what you said makes me eager. I hope you can generously teach me and show me how to use it!”

Xiao Hei said: “Since you have asked, how can I be stingy? Let’s take the Print function as an example; we can use it to output ‘Quiet Night Thoughts’ to the display.”

After saying this, Xiao Hei skillfully opened PyCharm, and the keyboard clicked as a simple Python program appeared.

Code for “Quiet Night Thoughts” 1

print("床前明月光,疑是地上霜。举头望明月,低头思故乡。")

After clicking the run button, “Quiet Night Thoughts” appeared in the compilation box.

床前明月光,疑是地上霜。举头望明月,低头思故乡。

Xiaoming couldn’t help but admire, saying: “This Python indeed has some skills. I imagine Li Taibai would applaud. However, all four lines are on one line; it doesn’t look good. Can it be changed to two lines?”

Xiao Hei said: “This is not difficult; you can use two print statements.” After saying this, he casually modified the program, and indeed, the effect of two lines appeared.

Code for “Quiet Night Thoughts” 2

print("床前明月光,疑是地上霜。")print("举头望明月,低头思故乡。")

Xiao Hei continued: “With a slight modification, it can also be changed to one line per sentence.”

After saying this, he was about to move his hands. Xiaoming hurriedly stopped him, saying: “Xiao Hei, wait a moment. I observed your operation just now and already have the answer. Let me try it.”

So, he took the keyboard and made slight modifications to Xiao Hei’s program, using four print statements, and indeed, the effect of one line per sentence appeared.

Code for “Quiet Night Thoughts” 3

print("床前明月光,")print("疑是地上霜。")print("举头望明月,")print("低头思故乡。")

Running effect:

床前明月光,疑是地上霜。举头望明月,低头思故乡。

Xiao Hei said: “People say you are exceptionally intelligent, able to understand three things from one; indeed, it is true.”

Xiaoming asked: “Earlier, you mentioned the ‘Print function’; what does this Print mean? What is a function?”

Xiao Hei said: “Translating it directly into our language, Print means ‘to print’, but this ‘print’ is not the same as the printer’s ‘print’; it is more appropriate to translate it as ‘display’. As for functions, let’s set that aside for now; you will understand it better with more practice.”

Xiaoming frowned and said: “If it doesn’t relate to printers, why not just use ‘display’? Wouldn’t that be more convenient?”

Xiao Hei laughed and said: “This is the naming of foreigners. Python is not a domestic product, and looking at languages around the world, there is no language as rich, concise, and practical as ours. Misunderstandings in translation are unavoidable. We don’t need to worry about it; just understand the meaning.”

The two continued to engage in programming, and before they knew it, several hours had passed. Xiaoming suddenly looked up and saw that it was already noon, exclaiming: “Oh no, this is bad!”What happens next? Stay tuned for the next episode.

Source Code and Material Acquisition

Programming is not easy. After clicking the ‘like’ button for the author at the bottom, scan the code to contact the editor to obtain the source code and materials.

Python for Beginners: A Detailed Introduction to Python

Leave a Comment