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
Python: compiler or Interpreter?Python: compiler or Interpreter?May 13, 2025 am 12:10 AM

Python is an interpreted language, but it also includes the compilation process. 1) Python code is first compiled into bytecode. 2) Bytecode is interpreted and executed by Python virtual machine. 3) This hybrid mechanism makes Python both flexible and efficient, but not as fast as a fully compiled language.

Python For Loop vs While Loop: When to Use Which?Python For Loop vs While Loop: When to Use Which?May 13, 2025 am 12:07 AM

Useaforloopwheniteratingoverasequenceorforaspecificnumberoftimes;useawhileloopwhencontinuinguntilaconditionismet.Forloopsareidealforknownsequences,whilewhileloopssuitsituationswithundeterminediterations.

Python loops: The most common errorsPython loops: The most common errorsMay 13, 2025 am 12:07 AM

Pythonloopscanleadtoerrorslikeinfiniteloops,modifyinglistsduringiteration,off-by-oneerrors,zero-indexingissues,andnestedloopinefficiencies.Toavoidthese:1)Use'i

For loop and while loop in Python: What are the advantages of each?For loop and while loop in Python: What are the advantages of each?May 13, 2025 am 12:01 AM

Forloopsareadvantageousforknowniterationsandsequences,offeringsimplicityandreadability;whileloopsareidealfordynamicconditionsandunknowniterations,providingcontrolovertermination.1)Forloopsareperfectforiteratingoverlists,tuples,orstrings,directlyacces

Python: A Deep Dive into Compilation and InterpretationPython: A Deep Dive into Compilation and InterpretationMay 12, 2025 am 12:14 AM

Pythonusesahybridmodelofcompilationandinterpretation:1)ThePythoninterpretercompilessourcecodeintoplatform-independentbytecode.2)ThePythonVirtualMachine(PVM)thenexecutesthisbytecode,balancingeaseofusewithperformance.

Is Python an interpreted or a compiled language, and why does it matter?Is Python an interpreted or a compiled language, and why does it matter?May 12, 2025 am 12:09 AM

Pythonisbothinterpretedandcompiled.1)It'scompiledtobytecodeforportabilityacrossplatforms.2)Thebytecodeistheninterpreted,allowingfordynamictypingandrapiddevelopment,thoughitmaybeslowerthanfullycompiledlanguages.

For Loop vs While Loop in Python: Key Differences ExplainedFor Loop vs While Loop in Python: Key Differences ExplainedMay 12, 2025 am 12:08 AM

Forloopsareidealwhenyouknowthenumberofiterationsinadvance,whilewhileloopsarebetterforsituationswhereyouneedtoloopuntilaconditionismet.Forloopsaremoreefficientandreadable,suitableforiteratingoversequences,whereaswhileloopsoffermorecontrolandareusefulf

For and While loops: a practical guideFor and While loops: a practical guideMay 12, 2025 am 12:07 AM

Forloopsareusedwhenthenumberofiterationsisknowninadvance,whilewhileloopsareusedwhentheiterationsdependonacondition.1)Forloopsareidealforiteratingoversequenceslikelistsorarrays.2)Whileloopsaresuitableforscenarioswheretheloopcontinuesuntilaspecificcond

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool