Home >Backend Development >Python Tutorial >The magical 'Hello World' - starting the programming journey
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.
""" 第一个Python程序 - hello world Author: Python当打之年 """
print('hello world!') # 输出 hello world!
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:
同样可以输出 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']
Python的标识符可以作为变量名、函数名、类名、模块名以及其他对象的名称等,标识符命名时有以下几点需要注意:
标识符由字母、数字、下划线组成,如下所示均为符合规则的标识符:
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等。
. 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.
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 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!