博主都是在Jupyter Notebooks上进行练习的,如有想要使用Jupyter Notebooks, 请点击这里 直接上代码: import seaborn as snstips = sns.load_dataset('tips') print(tips.head())结果如下: 使用distplot(): print(sns.distplot(tips['total_bill']))结果如下: # kde: Whether to plot a gaussian kernel density estimate # bins: Specification of hist bins. If unspecified, as reference rule is used that tries to find...
LeetCode 69. x 的平方根 实现 int sqrt(int x) 函数。 计算并返回 x 的平方根,其中 x 是非负整数。 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去。 示例 1: 输入: 4 输出: 2 示例 2: 输入: 8 输出: 2 说明: 8 的平方根是 2.82842…, 由于返回类型是整数,小数部分将被舍去。 Code def mySqrt(self, x: int) -> int:l,r,res=0,x,-1while l<=r:mid=(l+r)//2mid_val=mid*midif mid_val<=x:#如果大于的话是不合理的r...
在Python中,我们可以使用int()将String转换为int。# String num1 = "88"# <class str> print(type(num1))# int num2 = int(num1)# <class int> print(type(num2))例:一个将两个数字相加的Python示例。 1.1直接添加两个String。 num1 = "1" num2 = "2"num3 = num1 + num2print(num3) 输出量12 1.2使用int()再试一次 num1 = "1" num2 = "2"# convert string to int num3 = int(num1) + int(num2)print(num3) 输出量3
name = "xiaoming" year = 2012 m = 12 d = 12print("欢迎"+ name + "登录,今天是" + str(year) + "年" + str(m) + "月" + str(d) + "月") #所有字符强制转换为str,然后通过+连接打印出来 print("欢迎%s登录,今天是%s年%s月%s日"%(name,year,m,d)) #当打印的内容有多个变量时,为了高效打印出来,可以先用%s代替变量,直接在""中替换,然后在最后用%()变量按顺序填写用","分割 print("欢迎{name1}登录,今天是{ye}年{mo}月...
原文链接:http://www.juzicode.com/archives/2736 错误提示: 字符串到10进制转换时提示:ValueError: invalid literal for int() with base 10: ‘1a’ #juzicode.com/vx:桔子code a = int('135',10) print('a=',a) b = int('1a',10) print('b=',b)a= 135 --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipyth...
[Python GUI]Python内置图形界面tkinter Hand-Eye Coordination--游戏实战1 游戏介绍关键词TodoList代码详解 游戏介绍 本文实现的是一种成为hand-eye coordination的游戏的简单实现。hand-eye coordination就是一种锻炼手眼协调控制的游戏,有些类似于别踩白块,虽然比别踩白块要简单,但是思想是一样的。 代码实现了可以通过设置画布大小和网格多少来初始化UI,并设置方块下落速度,以改变游戏难度,还可以设置方块出现多少次之后...
import tkinter import tkinter.messageboxroot = tkinter.Tk() root.title('BMI计算器') root.geometry('400x400')bmi = tkinter.StringVar()label = tkinter.Label(root,text='BMI判断') label.place(x=10,y=10,height=30,width=80)labelName = tkinter.Label(root,text='姓名') labelName.place(x=10,y=60,height=20,width=80)labelAge = tkinter.Label(root,text='年龄') labelAge.place(x=10,y=110,height=20,width=80)labelW...
本人使用的anaconda,python版本为3.6,之前是基于pip,安装的python3.5直接就可以pip install pyinstaller ,但是使用py3.6版本时却失败,报错如下: 后查阅资料发现py3.6版本后enum34已经不兼容,故无法安装,将该包直接卸载后就可以使用。尝试查看自己是否安装enum,在窗口输入pip list发现如下: 卸载enum,pip uninstall enum34.卸载后,再安装pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple/ 我这里用...
报错: from tkinter import *img = PhotoImage(file = r'D:\test\hero\暗黑元首\暗黑元首.jpg') lable_show = Label(frame_show,imag = img)解决:首先安装PIL库,使用pip命令 pip install pillow 然后使用PIL库获得ImageTk.PhotoImage对象代替tk.PhotoImage对象即可 from PIL import Image,ImageTkimg = ImageTk.PhotoImage(Image.open(r'D:\test\hero\暗黑元首\暗黑元首.jpg')) lable_show = Label(frame_show,imag = img)
代码如下: import xlwings as xl excel =xl.App() wb=excel.books.add() 运行报错pywintypes.com_error: (-2147221005, 无效的类字符串, None, None) 排查与解决步骤: 1)查询资料,未找到同样场景,但同类报错,win32com.client.Dispatch()使用时出现过,有提到安装wps版本影响 2)基于以上查询结果,初步定位可能是wps兼容性问题,首先把默认wps打开xlsx取消掉,然后安装office 3)再次运行,正常。
import xlwings as xl exccel = xl.App() 运行报错:提示找不到pywintypes模块 问题排查与解决过程记录: 1)pip install pywintypes,提示未有此模块; 2)查询资料发现此模块在pywin32模块中,pip install pywin32,提示已安装pywin32此模块 3)查询资料网上一些解决方案是手动安装pywin32,已做好下载安装准备 4)下载安装包过程中,发现此篇内容https://www.pianshen.com/article/81261730493/,提到pywin32在223版本以后都需...
基于Python开发工具pycharm的tkinter模块开发简单的计算器程序 提示: Tkinter模块(Tk 接口)是 Python 的标准 Tk GUI 工具包的接口,一般是自带的内置模块,不需要下载安装。 如果没有,可以在cmd命令窗口通过输入pip install tkinter 命令进行安装 文章目录 基于Python开发工具pycharm的tkinter模块开发简单的计算器程序一. 问题分析和任务定义二. 逻辑设计三.设计步骤1.引入需要的库2.创建显示窗口3.定义计算算式和结果变量4.创建...
一篇可以参考的关于type hint的文章 Type hints cheat sheet (Python 3) type hint in class 当在父类方法中调用子类才定义的类属性时,可以在父类中先加入type hint,减少pycharm提示找不到这个类属性 class FeatureCommon:config: dictexecute_kwargs: dictfeature_name: strfeature_class: Type[TSFeatures]几个基元格式 Tuple type; Tuple[X, Y] is the type of a tuple of two items with the first item of type X and the s...
1、Treeview的基本属性# -*- encoding=utf-8 -*-import tkinter from tkinter import * from tkinter import ttkif __name__ == __main__:passwin = tkinter.Tk() # 窗口win.title(南风丶轻语) # 标题screenwidth = win.winfo_screenwidth() # 屏幕宽度screenheight = win.winfo_screenheight() # 屏幕高度width = 1000height = 500x = int((screenwidth - width) / 2)y = int((screenheight - height) / 2)win.geometry({}x{}...
1、绝对和相对位置# -*- encoding=utf-8 -*- import tkinter from tkinter import *if __name__ == __main__:win = tkinter.Tk() # 窗口win.title(南风丶轻语) # 标题screenwidth = win.winfo_screenwidth() # 屏幕宽度screenheight = win.winfo_screenheight() # 屏幕高度width = 400height = 500x = int((screenwidth - width) / 2)y = int((screenheight - height) / 2)win.geometry({}x{}+{}+{}.format(width, height, x, ...