搜索结果
-
缩进
Python 不使用 {} 来控制类、函数、逻辑判断等,而是使用缩进,缩进的空格可变。如下所示:if True: print(True)else: print(False)
-
输入输出
Python 输出使用 print(),内容加在括号中即可。如下所示:print('Hello Python')Python 提供了一个 input(),可以让用户输入字符串,并存放到一个变量里。如下所示:name = input()print('Hi',name)
-
运算符优先级
运算符优先级
-
数据类型
整数:可以为任意大小、包含负数浮点数:就是小数字符串:以单引号 '、双引号"、三引号 ''' 或 """括起来的文本布尔:只有 True、False 两种值空值:用 None 表示变量:是可变的常量:不可变
-
注释
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。
-
Thinkphp各版本的PHP要求
ThinkPHP 8.0:运行环境要求PHP8.0+,兼容PHP8.3ThinkPHP 6.1:运行环境要求PHP7.2+,兼容PHP8.1ThinkPHP 6.0:运行环境要求PHP7.2+,兼容PHP8.1ThinkPHP 5.1:运行环境要求PHP5.6+,兼容PHP8.0ThinkPHP 5.0:运行环境要求PHP5.4+,兼容PHP7.3
-
Thinkphp5.1路径常量
1 配置文件位置根目录/config/template.php2 配置文件内容<?php// +----------------------------------------------------------------------// | ThinkPHP [ WE CAN DO IT JUST THINK ]// +----------------------------------------------------------------------// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reser
-
Thinkphp5.0路径常量
1 配置文件位置根目录/application/模块名/config.php2 配置文件内容<?php//配置文件return [ // 后台视图输出字符串内容替换 'view_replace_str' => [ '__PUBLIC__' => '/', '__STATIC__' => '/static', '__CONSOLE__' => '/static/console', '__CONSOLE_CSS__' => '/static/console/css', '__CONSOLE_IMAGES__' => '/static/console/ima
-
获取网络图片的宽度和高度
// 获取网络图片的宽度和高度if (!function_exists('widht_gt_height')) { function widht_gt_height($webImage) { // 获取图片信息 $imageInfo = @getimagesize($webImage); // 检查是否成功获取图片信息 if ($imageInfo === false) { return true; } // 提取图片宽度和高度 $width = 0; if (isset($imageInfo[0]) && !empty($imageInfo[0])) { $width = $
-
将网络图片保存到指定的目录下
/** * 将网络图片保存到指定的目录下 * param $url 网络图片地址,例如:http://example.com/image.jpg * param $savePath 保存的图片路径,例如:/path/to/save/image.jpg*/if(!function_exists('save_image_from_url')) { function save_image_from_url($url, $savePath) { // 获取远程图片内容 $imageContent = file_get_contents($url); if ($imageContent === fals
-
生成一个随机的图片名
/** * 生成一个随机的图片名 * param $type 文件名的后缀 */if(!function_exists('get_image_file_name')) { function get_image_file_name($type = 'png') { if (in_array($type, ['png', 'jpg', 'jpeg'])) { return time().rand(1,99999).'.'.$type; } return ''; }}
-
把字符串中第一个出现的子字符串替换成指定的内容
/** * 把字符串中第一个出现的子字符串替换成指定的内容 * @param string $string 字符串 * @param string $substring 子字符串 * @param string $replacement 要替换的内容 */if(!function_exists('replace_first_sub_string')) { function replace_first_sub_string($string, $substring, $replacement) { $position = strpos($string, $substring); if ($posi
-
用户点击关闭窗口
<script> layui.use(['form', 'jquery', 'laydate', 'upload'], function () { var $ = layui.jquery; // 用户点击关闭窗口 $('.close_this').click((res) => { var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引 parent.location.reload();//刷新父页面,注意一定要在关闭当前iframe层之前执行刷新 parent.layer.close(in
-
traits按钮
<?phpnamespace app\admin\traits;use think\facade\Session;use think\Db;// 按钮操作类trait BtnTrait { /** * 显示删除按钮 * @param string $route 操作路径,格式:控制器/方法 * @param int $id 数据ID */ public function deleteButton($route, $id) { // 检测参数 if (empty($id) || empty($route)) { return ''; } $bool = $this->getUserA
-
点击显示编辑弹窗
// 显示编辑的弹窗$(".edit-btn").click(function(event){ // 阻止 <a> 标签的默认点击行为(即不跳转到链接) event.preventDefault(); // 获取当前被点击的 <a> 标签的 href 属性 var href = $(this).attr("href"); if (href == '') { return false; } layer.open({ type: 2, title: '编辑', offset: 'auto', area: ['900px', '650px'], content: href,