search
HomeBackend DevelopmentPython TutorialThe magical 'Hello World' - starting the programming journey

##01






#Hello World
Hello World as

The C Programming Language# The first demonstration program in ## is very famous. Later programmers continued this habit when learning programming or debugging equipment. It can be considered the beginning of the programming journey.

The magical 'Hello World' - starting the programming journeyThe following program output: Hello World!
"""
第一个Python程序 - hello world
Author: Python当打之年
"""
print('hello world!')
# 输出 hello world!

print()

Function is used to print output, which is in the python program The most common function.


We save the

above code as hello.py file , then you can also enter the following command in the terminal:

##>>>
python hello.py

同样可以输出 Hello World!,以下是一些其他输出的例子

"""
第一个Python程序 - hello world
Author: Python当打之年
"""
a = 2
print(a)
# 输出 2
b = '你好'
print(b)
# 输出 你好
c = (1,2,3)
print(c)
# 输出 (1,2,3)
d = [1,2,'3']
print(d)
# 输出 [1,2,'3']
The magical 'Hello World' - starting the programming journey
02






Python 标识符

Python的标识符可以作为变量名、函数名、类名、模块名以及其他对象的名称等,标识符命名时有以下几点需要注意:

The magical 'Hello World' - starting the programming journey
  • 标识符由字母、数字、下划线组成,如下所示均为符合规则的标识符:

    name
    your_age
    str123
    User
    BOOK
    book_name
    _base


  • 标识符不能以数字开头

    1name
    12User
    000BOOK
    678user_age
  • 标识符严格区分大小写,以下代表五个不同的标识符:

    name
    Name
    NAme
    NAMe
    NAME
  • 以下划线开头的标识符是有特殊意义(后续会详解

  • 标识符可以是汉字,但是尽量不要这么用

  • 标识符不能和 python 关键字(保留字)相同,以下指令可以输出python所有的关键字:

    import keyword
    print(keyword.kwlist)
    #['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

常用命名规则:

  • 见名知意

    起一个有意义的名字,尽量做到看一眼就知道是什么意思,例如: 定义名字可以用name,定义年龄可以用age,定义学生姓名可以用student_name等。

  • 驼峰命名法

    小驼峰式命名法:第一个单词以小写字母开始;第二个单词的首字母大写,例如:studentName、studentAge等。

    大驼峰式命名法:每一个单词的首字母都采用大写字母,例如:StudentName、StudentAge等。

The magical 'Hello World' - starting the programming journey
#03






#Python Comments
## A good memory is not as good as a bad writing

. In our daily exercises, the code is relatively simple and the number of lines is relatively small, which does not reflect the importance of comments. In actual work, a project is often written by many programmers with thousands or even hundreds of thousands or millions of lines of code. If there are no comments at this time, not only will the problem not be solved efficiently, but the question will also be consumed. It consumes both manpower and material resources, so everyone must develop the habit of writing comments.

The magical 'Hello World' - starting the programming journey
##Python comments are mainly divided into the following two categories:


#Single line comment
  • You can only comment one line of content, starting with #:

    # hello world!

  • 多⾏注释

    注释多⾏内容,以下三种方式均可以实现多行注释

  • # 以下为多行注释1
    """
    第一个Python程序 - hello, world
    Author: Python当打之年
    """
    # 以下为多行注释2
    '''
    第一个Python程序 - hello, world
    Author: Python当打之年
    '''
    # 以下为多行注释3
    # 第一个Python程序 - hello, world
    # Author: Python当打之年

小提示:选定要注释的代码段,使用快捷键ctrl+/,可一次性注释该代码段,重复操作可取消注释。

The magical 'Hello World' - starting the programming journey

The above is the detailed content of The magical 'Hello World' - starting the programming journey. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:Python当打之年. If there is any infringement, please contact admin@php.cn delete
The Main Purpose of Python: Flexibility and Ease of UseThe Main Purpose of Python: Flexibility and Ease of UseApr 17, 2025 am 12:14 AM

Python's flexibility is reflected in multi-paradigm support and dynamic type systems, while ease of use comes from a simple syntax and rich standard library. 1. Flexibility: Supports object-oriented, functional and procedural programming, and dynamic type systems improve development efficiency. 2. Ease of use: The grammar is close to natural language, the standard library covers a wide range of functions, and simplifies the development process.

Python: The Power of Versatile ProgrammingPython: The Power of Versatile ProgrammingApr 17, 2025 am 12:09 AM

Python is highly favored for its simplicity and power, suitable for all needs from beginners to advanced developers. Its versatility is reflected in: 1) Easy to learn and use, simple syntax; 2) Rich libraries and frameworks, such as NumPy, Pandas, etc.; 3) Cross-platform support, which can be run on a variety of operating systems; 4) Suitable for scripting and automation tasks to improve work efficiency.

Learning Python in 2 Hours a Day: A Practical GuideLearning Python in 2 Hours a Day: A Practical GuideApr 17, 2025 am 12:05 AM

Yes, learn Python in two hours a day. 1. Develop a reasonable study plan, 2. Select the right learning resources, 3. Consolidate the knowledge learned through practice. These steps can help you master Python in a short time.

Python vs. C  : Pros and Cons for DevelopersPython vs. C : Pros and Cons for DevelopersApr 17, 2025 am 12:04 AM

Python is suitable for rapid development and data processing, while C is suitable for high performance and underlying control. 1) Python is easy to use, with concise syntax, and is suitable for data science and web development. 2) C has high performance and accurate control, and is often used in gaming and system programming.

Python: Time Commitment and Learning PacePython: Time Commitment and Learning PaceApr 17, 2025 am 12:03 AM

The time required to learn Python varies from person to person, mainly influenced by previous programming experience, learning motivation, learning resources and methods, and learning rhythm. Set realistic learning goals and learn best through practical projects.

Python: Automation, Scripting, and Task ManagementPython: Automation, Scripting, and Task ManagementApr 16, 2025 am 12:14 AM

Python excels in automation, scripting, and task management. 1) Automation: File backup is realized through standard libraries such as os and shutil. 2) Script writing: Use the psutil library to monitor system resources. 3) Task management: Use the schedule library to schedule tasks. Python's ease of use and rich library support makes it the preferred tool in these areas.

Python and Time: Making the Most of Your Study TimePython and Time: Making the Most of Your Study TimeApr 14, 2025 am 12:02 AM

To maximize the efficiency of learning Python in a limited time, you can use Python's datetime, time, and schedule modules. 1. The datetime module is used to record and plan learning time. 2. The time module helps to set study and rest time. 3. The schedule module automatically arranges weekly learning tasks.

Python: Games, GUIs, and MorePython: Games, GUIs, and MoreApr 13, 2025 am 12:14 AM

Python excels in gaming and GUI development. 1) Game development uses Pygame, providing drawing, audio and other functions, which are suitable for creating 2D games. 2) GUI development can choose Tkinter or PyQt. Tkinter is simple and easy to use, PyQt has rich functions and is suitable for professional development.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment