Python Beginner: A 30-Day Guide for Absolute Beginners

Recently, I often get asked: “I can’t even remember all the Excel formulas, can I learn programming?” As someone who once thought of “variables” as “changing weights,” I want to say: Python is truly the “Mandarin” of the programming world. If you can type on your phone, 30 days is enough for you to get started.

Python Beginner: A 30-Day Guide for Absolute Beginners

Days 1-3: Get Python on Your Computer

Don’t be intimidated by “installation”; this step is easier than installing WeChat.

Open your browser and search for “Python official website,” then click on the logo that looks like a snake. Find “Downloads,” and the system will automatically recommend the version suitable for your computer. Just click to start downloading, similar to saving an image.

When installing, remember to check “Add Python to PATH”; this step is like filling in the delivery address for a package, otherwise, your computer won’t find the newly installed Python. After that, just keep clicking “Next,” and once the progress bar is complete, you will have your programming tool.

To verify if it’s installed correctly: press Win+R, type “cmd” to open the command prompt, type “python” and hit enter. If a string of text with a version number appears, congratulations, Python is now installed on your computer.

Python Beginner: A 30-Day Guide for Absolute Beginners

Days 4-7: Say “Hello” with Code

Open the built-in Notepad on your computer, type print (“你好,世界”), and when saving, change the file name to “hello.py”. Make sure the extension is .py, just like labeling a file correctly.

Find this file, hold Shift and right-click on it, select “Open PowerShell window here,” type “python hello.py” and hit enter. The screen will display “你好,世界”. This line of code means you are holding up a sign that says this sentence—print means “display,” and the content in quotes is what you want to say.

Try changing the content in the quotes, for example, to “今天吃火锅,” and run it again. Isn’t it magical? Spend these days playing with this, inputting random things to see what the computer displays, and get a feel for it.

Days 8-12: Let the Computer Do the Math

Python calculates faster than a calculator. Open the previous editor, type print (100+200), and running it will directly show 300. Addition, subtraction, multiplication, and division are represented by +, -, and /, just like math symbols.

Try calculating the cost of groceries: potatoes at 3.5 yuan per jin for 2 jins, eggs at 6 yuan per jin for 1.5 jins, input print (3.5*2 + 6*1.5), and instantly know you need to spend 16 yuan.

You can also let the computer remember things, for example, x=5, y=3, then print (x+y), and the computer will remember x is 5, y is 3, and calculate 8. Here, x and y are “variables,” like boxes that can hold things, and you can change the contents at any time.

Days 13-18: Tips for Renaming Files

Do you have a bunch of photos named “IMG_20230101.jpg” on your phone? Python can batch rename them to “春节 – 1.jpg”, “春节 – 2.jpg”.

First, create a folder and put the photos you want to rename inside. Then write a few lines of code:

import os<br/>path = "your folder path"<br/>files = os.listdir(path)<br/>for i, file in enumerate(files):<br/>    old = path + "/" + file<br/>    new = path + "/春节 - " + str(i+1) + ".jpg"<br/>    os.rename(old, new)

This code means: first find your folder (path), list all the files inside (files), and then rename them one by one (rename), starting from 1.

When changing the path, remember to replace backslashes with forward slashes, for example, “D:\photos” should be written as “D:/photos”. It’s best to back up the files before running, in case you input the wrong address and need to recover them.

Days 19-25: Create a Simple Notepad

Want the computer to help you keep a diary? Just write a small program.

The code looks something like this:

content = input("今天发生了什么?")<br/>with open("日记.txt", "a") as f:<br/>    f.write(content + "\n")<br/>print("记录好啦!")

After running, the computer will pop up an input box for you to type. After you finish and hit enter, the content will be saved in “日记.txt”. Each day’s content will automatically start a new line, and after a month, you will have an electronic diary.

Here, input means “receive input,” open means “open file,” and “a” means “append content,” just like continuing to write in a notebook without erasing what was previously written.

Days 26-30: Give Yourself a Quiz

In the last few days, do a comprehensive exercise: let the computer randomly generate 10 addition problems, score points for correct answers, and report the final score.

The core code logic:

import random<br/>score = 0<br/>for i in range(10):<br/>    a = random.randint(1, 100)<br/>    b = random.randint(1, 100)<br/>    ans = int(input(f"{a}+{b}=?"))<br/>    if ans == a + b:<br/>        score += 10<br/>print(f"总分 {score} 分")

This code uses random numbers (random), loops (for), and conditions (if), just like assembling the parts you learned into a small machine. If you answer incorrectly during the run, points will be deducted; if you answer correctly, points will be added. Doesn’t it feel like doing math problems as a child?

After 30 days, you may not become a programming expert, but you will definitely understand: Python is not just a tool for programmers; it’s like a universal assistant—it can help calculate reports, assist teachers in grading, and help moms organize phone photos. The key is not how much code you remember, but how to use it to solve small problems around you.

If one day you find that a few lines of code you wrote saved you 1 hour of repetitive work, congratulations, you have crossed the first threshold of programming.

Leave a Comment