Python基础
-
注释
Python 中单行注释使用 #,多行注释使用三个单引号(''')或三个双引号(""")。如下所示:# 我是单行注释'''我是多行注释我是多行注释'''"""我是多行注释我是多行注释"""
-
python怎么获取时间
在Python中获取时间可以使用内置的 datetime 模块。具体来说,你可以按照以下步骤来获取当前时间:import datetime# 获取当前日期和时间current_datetime = datetime.datetime.now()# 获取当前日期current_date = datetime.date.today()# 获取当前时间current_time = datetime.datetime.now().time()# 打印结果print("当前日期和时间:", current_datetime)print("当前日期:", current_date)print("当前时间:
-
字符串列表相互转换
1 range()函数作用range(5)生成的序列是从0开始小于5的整数:>>> list(range(5))[0, 1, 2, 3, 4]2 字符串转列表str1 = "hi hello world"print(str1.split(" "))输出:['hi', 'hello', 'world']3 列表转字符串l = ["hi","hello","world"]print(" ".join(l))输出:hi hello world
-
部署上线
1 生成项目依赖文件# 项目根目录下,运行命令 pip freeze > ./requirements.txt2 根据项目依赖文件安装第三方库pip install -r requirements.txt
-
Python2和Python3的区别
(1) 在 Python2 中,print 是一条语句,而 Python3 中作为函数存在。print 'Hello world' // 这是Python2的语法print ('Hello world') // 这是Python3的语法(2) Python2没有布尔型,数字 0 表示 False,1 表示 True。(3) Python3种True 和 False 是关键字,它们的值还是 1 和 0,可以和数字相加。(4) Python2 中有整型int 和长整型 Long(5) Python3中只有一种整数类型 int,表示为长整型,没有 Long。