Chapter 1: 欢迎来到Python的世界 | Welcome to the World of Python
第一章:欢迎来到Python的世界
Welcome to the World of Python
想象一下,在你面前有一扇巨大的魔法门,门上刻着一行神秘的文字。这不是普通的门,而是通往数字世界的神奇入口。而今天,我们要学习的Python,就是打开这扇门的魔法钥匙!
Imagine standing before a giant magical door, with mysterious words carved upon it. This isn't just any ordinary door—it's a portal to the digital world. And today, the magic key to open this door is Python!
你可能会好奇:什么是Python?它为什么叫这个名字?别着急,让我们慢慢来揭开它的神秘面纱。Python的中文意思是"蟒蛇",但不要被这个名字吓到——它和真正的蟒蛇可没有任何关系哦!这个有趣的名字其实来源于一个幽默的典故:Python的创始人吉多·范罗苏姆(Guido van Rossum)在创造这门语言时,正在观看一部叫《蒙提·派森的飞行马戏团》(Monty Python's Flying Circus)的英国喜剧节目。这个节目既有趣又有点傻,充满了各种稀奇古怪的表演。范罗苏姆觉得,这个名字和他创造的编程语言有着相同的气质——既强大又充满趣味!所以他就用Python来命名这门语言了。
You might be wondering: What exactly is Python? Why is it called that? Don't worry, let's slowly uncover its mysteries together. The Chinese word for Python is "蟒蛇" (mangshe), which means "python" or "boa constrictor." But don't be scared by this name—it has absolutely nothing to do with real snakes! This fun name actually comes from a humorous story: When Guido van Rossum created this programming language, he was watching a British comedy show called "Monty Python's Flying Circus." This show was both funny and a bit silly, full of all sorts of bizarre performances. Van Rossum thought the name matched the spirit of the programming language he was creating—powerful yet playful! So he named the language Python.
Python是什么?
What is Python?
Python是一种编程语言。听到"语言"这个词,你会想到什么?对了,我们平时说话用的中文、英语、日语都是语言,它们用来让人与人之间进行交流。而编程语言呢?它是一种用来和计算机"对话"的语言!
Python is a programming language. When you hear the word "language," what comes to mind? Right! The Chinese, English, and Japanese we speak every day are all languages, used for communication between people. And a programming language? It's a language for "talking" with computers!
想象一下,如果你要告诉一只聪明的小狗去拿球,你需要用狗能理解的方式发出指令,比如"去!拿球!"。同样地,如果你想让计算机帮你完成一项任务,比如计算"1加1等于几",或者自动整理文件夹里的文件,你就需要用计算机能理解的方式——也就是编程语言——来发出指令。
Imagine if you wanted to tell a smart little dog to fetch a ball. You would need to give commands in a way the dog can understand, like "Go! Get the ball!" Similarly, if you want a computer to help you with a task—perhaps calculating "what is 1 plus 1," or automatically organizing files in a folder—you need to give commands in a way the computer understands: through a programming language!
而Python就是众多编程语言中的一种,它特别适合初学者学习和使用。为什么这么说呢?让我们继续往下看!
And Python is just one of many programming languages. But why is it especially suitable for beginners? Let's find out!
为什么选择Python?
Why Choose Python?
在我们正式开始学习Python之前,让我们先来认识一下Python的"超能力"。这些超能力让Python成为了全球最受欢迎的编程语言之一,甚至连NASA(美国国家航空航天局)和Google这样的超级大公司都在使用它!
Before we start learning Python, let's discover Python's "superpowers." These special abilities have made Python one of the most popular programming languages in the world—even super companies like NASA and Google use it!
超能力一:简单易学,像说话一样自然
Superpower One: Easy to Learn, Natural as Speaking
Python的语法(也就是写代码的规则)设计得非常简单和人性化。你可能听说过其他编程语言,比如Java或者C++,它们写起代码来非常复杂,有时候一个简单的功能需要写很长很长的代码。但是Python不一样!Python的代码看起来更像我们平时说的话,读起来更像是读一篇短文,而不是在看一堆复杂的符号。
Python's syntax (the rules for writing code) is designed to be very simple and user-friendly. You might have heard of other programming languages like Java or C++, which can be quite complex to write—sometimes a simple function requires very long code. But Python is different! Python code looks more like our everyday speech, reading more like a short passage rather than a jumble of complicated symbols.
比如说,如果我们想对计算机说"你好,小朋友!",在不同语言中是这样写的:
For example, if we want to tell the computer "Hello, little friend!", here's how it would look in different languages:
C++语言: ```cpp #include <iostream> int main() { std::cout << "Hello, little friend!" << std::endl; return 0; } ```
Java语言: ```java public class Hello { public static void main(String[] args) { System.out.println("Hello, little friend!"); } } ```
Python语言: ```python print("Hello, little friend!") ```
哇!看到了吗?Python只需要一行代码就能完成的事情,其他语言可能需要好几行甚至几十行代码!这就像是,你只需要说"你好"就能打招呼,而不用背诵一长串复杂的礼仪用语。这就是Python的第一个超能力:简洁。
Wow! See the difference? Python can accomplish in just one line what might take several or even dozens of lines in other languages! It's like how you just need to say "hello" to greet someone, instead of reciting a long list of complex etiquette phrases. This is Python's first superpower: brevity.
超能力二:功能强大,无所不能
Superpower Two: Powerful and Capable of Anything
虽然Python写起来简单,但它能干的事情可一点都不简单!Python就像是一个万能的工具箱,里面装满了各种各样的神奇工具:
Even though Python is simple to write, what it can do is anything but simple! Python is like a universal toolbox filled with all kinds of magical tools:
数据分析与人工智能:你有没有想过,为什么手机能认识你的脸?为什么音乐软件能推荐你喜欢的歌曲?为什么自动驾驶汽车能识别行人?这些神奇功能的背后,很多都是用Python实现的!Python是数据科学家和人工智能工程师最喜欢的工具。
Data Analysis and Artificial Intelligence: Have you ever wondered why your phone can recognize your face? Why music apps can recommend songs you like? Why self-driving cars can identify pedestrians? Behind many of these magical features, Python is at work! Python is the favorite tool of data scientists and AI engineers.
网站开发:你平时浏览的网页,比如百度、淘宝、B站,它们背后的服务器程序有很多都是用Python写的。Python可以快速地搭建起一个功能强大的网站。
Website Development: The websites you browse every day, like Baidu, Taobao, and Bilibili—many of their server programs are written in Python. Python can quickly build powerful websites.
自动化办公:这是我们这本书的重点!Python可以帮你自动处理Excel表格、自动发送邮件、自动整理文件、自动生成报告……想象一下,如果有一个小助手能帮你完成那些重复性的、繁琐的工作,你就能有更多时间去学习和玩耍了!
Office Automation: This is the focus of our book! Python can help you automatically process Excel sheets, send emails, organize files, generate reports... Imagine having a little helper that handles all those repetitive, tedious tasks, giving you more time for learning and playing!
游戏开发:很多有趣的小游戏也是用Python开发的。虽然Python不适合做那些画面超级精美的3A大作,但是用来做简单的2D游戏、学习游戏编程的原理,那是再合适不过了!
Game Development: Many fun small games are also developed with Python. While Python isn't suitable for those graphically stunning 3A games, it's perfect for making simple 2D games and learning game programming concepts!
科学研究:从天文观测到基因分析,从气候预测到药物研发,科学家们也在广泛使用Python来处理数据和进行科学计算。
Scientific Research: From astronomical observations to genetic analysis, from climate prediction to drug development, scientists widely use Python for data processing and scientific computing.
超能力三:社区强大,有问必答
Superpower Three: A Strong Community, Questions Always Answered
Python有一个超级大的"朋友圈"——全世界的Python程序员们组成了一个庞大的社区。当你遇到问题时,只需要在网上搜索一下,几乎总能找到答案。就像有一大群热心的魔法师随时准备帮助你!
Python has a huge "circle of friends"—Python programmers from around the world form a large community. When you encounter problems, just search online, and you'll almost always find answers. It's like having a group of helpful wizards ready to help you anytime!
而且,因为使用Python的人很多,所以各行各业的人都用Python写好了各种"工具包"(叫做库或模块)。想要处理Excel?有一个库可以帮你。想要发送邮件?也有一个库。想要制作图表?还是有一个库。这些现成的工具让你不需要从零开始,就像搭积木一样,把已经做好的积木块拼在一起,就能完成很厉害的作品!
Moreover, because so many people use Python, people from all walks of life have written various "toolkits" (called libraries or modules) in Python. Want to process Excel? There's a library for that. Want to send emails? There's a library for that too. Want to create charts? Still a library! These ready-made tools mean you don't need to start from scratch—like building with blocks, you just combine pre-made pieces to create something impressive!
Python小超人的自我介绍
Python Superhero's Self-Introduction
嗨!大家好!我是Python小超人!
Hi everyone! I'm Python Superhero!
很高兴认识你们!在接下来的旅程中,我将陪伴大家一起学习Python编程。让我先自我介绍一下吧:
I'm so happy to meet you all! During the journey ahead, I'll be accompanying you as we learn Python programming together. Let me introduce myself:
我出生于1991年,到现在已经30多岁了。你可能会觉得30多岁已经很老了,但对于一门编程语言来说,这正是"壮年"时期——既成熟稳定,又充满活力。在这30多年里,我见证了互联网的崛起、大数据的兴起、人工智能的爆发……每一次科技浪潮,我都没有落下,反而越来越受欢迎。
I was born in 1991, so I'm already over 30 years old. You might think 30+ is pretty old, but for