Python---random,time,PIL库

本文介绍了Python的random库,包括设置种子、生成随机整数和浮点数、列表随机选择等。同时,详细讲解了time模块的时间戳、日期格式化和睡眠函数。此外,还探讨了PIL库在图像处理中的应用,如创建、打开、显示、缩放和滤镜操作。这些内容对于Python编程和图像处理非常实用。

random库

random.seed(a=None, version=2)

设置随机种子,若不想让随机函数,有随机性,可以手动设置种子,以后每次随机出来的数字就会一样了


生成随机数字

random.randrange(stop)

random.randrange(start, stop[, step])

range()中随机挑选一个数字。

range(start, stop, step) 返回一个随机选择的元素。 这相当于 choice(range(start, stop, step)) ,但实际上并没有构建一个 range 对象。

random.randint(a, b)

在[a,b]中随机挑选一个整数


列表随机挑选元素

random.choice(seq)

从非空序列 seq 返回一个随机元素。 如果 seq 为空,则引发 IndexError

random.choices(population, weights=None, *, cum_weights=None, k=1)

population中选择替换,返回大小为 k 的元素列表。 如果 population 为空,则引发 IndexError

如果指定了 weight 序列,则根据相对权重进行选择。 或者,如果给出 cum_weights 序列,则根据累积权重(可能使用 itertools.accumulate() 计算)进行选择。 例如,相对权重[10, 5, 30, 5]相当于累积权重[10, 15, 45, 50]。 在内部,相对权重在进行选择之前会转换为累积权重,因此提供累积权

kyy@kyy-Legion-Y7000P-IRX9:~$ sudo apt update 命中:1 http://mirrors.aliyun.com/ubuntu focal InRelease 命中:2 http://mirrors.aliyun.com/ubuntu focal-security InRelease 命中:3 http://mirrors.aliyun.com/ubuntu focal-updates InRelease 命中:4 http://mirrors.aliyun.com/ubuntu focal-proposed InRelease 命中:5 http://mirrors.aliyun.com/ubuntu focal-backports InRelease 正在读取软件包列表... 完成 正在分析软件包的依赖关系树 正在读取状态信息... 完成 有 393 个软件包可以升级。请执行 ‘apt list --upgradable’ 来查看它们。 kyy@kyy-Legion-Y7000P-IRX9:~$ sudo apt upgrade 正在读取软件包列表... 完成 正在分析软件包的依赖关系树 正在读取状态信息... 完成 正在计算更新... 完成 The following security updates require Ubuntu Pro with 'esm-infra' enabled: libsoup-gnome2.4-1 libpython3.6-minimal python-twisted-core libcups2 libcurl4 gir1.2-soup-2.4 libapt-inst2.0 libssh-4 libpython3.6-dev libgs9 python-twisted-bin libpython3.6-stdlib libcdio17 libfcgi-perl python3-pil libpython3.6 python3.6 libapt-pkg5.0 libprocps6 libvpx5 libsoup2.4-1 python3.6-minimal python-cryptography cups-filters libglib2.0-dev-bin cups-ppdc libcupsmime1 libcurl4-openssl-dev libglib2.0-bin python-pkg-resources libglib2.0-dev ghostscript python-setuptools ghostscript-x libmysqlclient20 libgs9-common cups-filters-core-drivers libcupsppdc1 ca-certificates cups-bsd python-idna cups-core-drivers cups-daemon python3.6-dev python-twisted libcupsimage2 libpoppler73 cups curl libcupscgi1 cups-client cups-ipp-utils libglib2.0-0 python-pil libcurl3-gnutls libssl1.0.0 Learn more about Ubuntu Pro at https://ubuntu.com/pro 下列软件包的版本将保持不变: appstream colord cups cups-bsd cups-client cups-core-drivers cups-daemon cups-filters cups-filters-core-drivers cups-ipp-utils cups-ppdc curl cython dash deja-dup docutils-common dpkg evolution-data-server fwupd fwupdate gazebo9 gazebo9-common gazebo9-plugin-base gdal-data ghostscript ghostscript-x gir1.2-freedesktop gir1.2-glib-2.0 gir1.2-gnomedesktop-3.0 gir1.2-gst-plugins-base-1.0 gir1.2-gtk-2.0 gir1.2-gtk-3.0 gir1.2-ibus-1.0 gir1.2-javascriptcoregtk-4.0 gir1.2-pango-1.0 gir1.2-polkit-1.0 gir1.2-rb-3.0 gir1.2-soup-2.4 gir1.2-webkit2-4.0 gjs glib-networking glib-networking-services gnome-calendar gnome-control-center gnome-control-center-data gnome-initial-setup gnome-power-manager gnome-session-bin gnome-session-common gnome-settings-daemon gnome-shell gnome-shell-common gnome-shell-extension-appindicator gnome-shell-extension-ubuntu-dock gnome-software gnome-software-common gnome-software-plugin-snap gnome-startup-applications gsettings-desktop-schemas gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-pulseaudio gstreamer1.0-x gtk-update-icon-cache gvfs gvfs-backends gvfs-bin gvfs-common gvfs-daemons gvfs-fuse gvfs-libs hplip hplip-data ibus ibus-gtk ibus-gtk3 libalgorithm-diff-xs-perl libappstream-glib8 libappstream4 libboost-atomic-dev libboost-chrono-dev libboost-container-dev libboost-context-dev libboost-coroutine-dev libboost-date-time-dev libboost-dev libboost-exception-dev libboost-fiber-dev libboost-filesystem-dev libboost-graph-dev libboost-graph-parallel-dev libboost-iostreams-dev libboost-locale-dev libboost-log-dev libboost-math-dev libboost-mpi-dev libboost-mpi-python-dev libboost-numpy-dev libboost-program-options-dev libboost-python-dev libboost-random-dev libboost-regex-dev libboost-serialization-dev libboost-stacktrace-dev libboost-system-dev libboost-test-dev libboost-thread-dev libboost-timer-dev libboost-tools-dev libboost-type-erasure-dev libboost-wave-dev libcairo-gobject-perl libcairo-perl libcups2 libcupsimage2 libcurl3-gnutls libcurl4 libcurl4-openssl-dev libdazzle-1.0-0 libebackend-1.2-10 libegl-mesa0 libfcgi-perl libfile-fcntllock-perl libfwupd2 libgail-3-0 libgail-common libgail18 libgazebo9 libgazebo9-dev libgbm1 libgcab-1.0-0 libgdal-dev libgirepository-1.0-1 libgjs0g libgl1-mesa-dri libglapi-mesa libglib-object-introspection-perl libglib-perl libglib2.0-0 libglib2.0-bin libglib2.0-dev libglib2.0-dev-bin libglibmm-2.4-1v5 libglx-mesa0 libgs9 libgs9-common libgstreamer-plugins-base1.0-0 libgstreamer-plugins-good1.0-0 libgtk-3-0 libgtk-3-bin libgtk2.0-0 libgtk2.0-bin libgtk2.0-dev libgtkmm-3.0-1v5 libhdf5-dev libhdf5-openmpi-dev libhpmud0 libhtml-parser-perl libhttp-date-perl libhttp-message-perl libibus-1.0-5 libignition-common libignition-common-dev libio-socket-ssl-perl libjavascriptcoregtk-4.0-18 liblocale-gettext-perl libnautilus-extension1a libnet-dbus-perl libnet-libidn-perl libnet-ssleay-perl libnetcdf-c++4 libnetcdf-cxx-legacy-dev libnetcdf-dev libopencv-calib3d-dev libopencv-contrib-dev libopencv-core-dev libopencv-dev libopencv-features2d-dev libopencv-flann-dev libopencv-highgui-dev libopencv-imgcodecs-dev libopencv-imgproc-dev libopencv-ml-dev libopencv-objdetect-dev libopencv-photo-dev libopencv-shape-dev libopencv-stitching-dev libopencv-superres-dev libopencv-ts-dev libopencv-video-dev libopencv-videoio-dev libopencv-videostab-dev libopencv-viz-dev libpango-1.0-0 libpango1.0-dev libpangocairo-1.0-0 libpangoft2-1.0-0 libpangomm-1.4-1v5 libpangoxft-1.0-0 libpcl-dev libpolkit-agent-1-0 libpolkit-gobject-1-0 libpython3-dev libpython3-stdlib libqt5concurrent5 libqt5core5a libqt5dbus5 libqt5designer5 libqt5designercomponents5 libqt5gui5 libqt5help5 libqt5network5 libqt5opengl5 libqt5opengl5-dev libqt5positioning5 libqt5printsupport5 libqt5qml5 libqt5quick5 libqt5quickparticles5 libqt5quicktest5 libqt5quickwidgets5 libqt5sensors5 libqt5sql5 libqt5sql5-sqlite libqt5svg5 libqt5test5 libqt5webchannel5 libqt5webkit5 libqt5webkit5-dev libqt5widgets5 libqt5xml5 libqtpropertybrowser4 libqwt-headers libqwt-qt5-6 libqwt-qt5-dev libreoffice-avmedia-backend-gstreamer libreoffice-base-core libreoffice-calc libreoffice-common libreoffice-core libreoffice-draw libreoffice-gnome libreoffice-gtk3 libreoffice-help-en-us libreoffice-help-zh-cn libreoffice-impress libreoffice-l10n-zh-cn libreoffice-math libreoffice-ogltrans libreoffice-style-breeze libreoffice-style-galaxy libreoffice-style-tango libreoffice-writer librhythmbox-core10 libsane-common libsane-hpaio libsane1 libsimbody-dev libsmbclient libsocket6-perl libsoup-gnome2.4-1 libsoup2.4-1 libssh-4 libsub-name-perl libtext-charwidth-perl libtext-iconv-perl libtinyxml2-dev libvtk6-dev libvtk6-qt-dev libvtk6.3 libvtk6.3-qt libwbclient0 libwebkit2gtk-4.0-37 libwww-perl libxml-libxml-perl libxml-parser-perl mutter nautilus nautilus-data orca pavucontrol perl perl-base policykit-1 printer-driver-brlaser printer-driver-gutenprint printer-driver-hpcups printer-driver-postscript-hp pyqt5-dev python-asn1crypto python-attr python-automat python-backports.functools-lru-cache python-cairo python-cffi-backend python-chardet python-concurrent.futures python-constantly python-cryptography python-dateutil python-docutils python-enum34 python-hyperlink python-idna python-ipaddress python-netifaces python-nose python-numpy python-olefile python-opengl python-openssl python-pam python-pil python-pkg-resources python-psutil python-pyasn1 python-pyasn1-modules python-pycryptodome python-pygments python-pyparsing python-roman python-service-identity python-setuptools python-sip python-sip-dev python-six python-subprocess32 python-tk python-tz python-u-msgpack python-wxgtk3.0 python-wxtools python-wxversion python-yaml python-zope.interface python3 python3-apt python3-brlapi python3-cairo python3-cffi-backend python3-crypto python3-cups python3-dbus python3-dev python3-distutils python3-gdbm python3-gi python3-gi-cairo python3-lib2to3 python3-markupsafe python3-minimal python3-netifaces python3-pil python3-protobuf python3-renderpm python3-reportlab python3-reportlab-accel python3-simplejson python3-systemd python3-uno python3-yaml qt5-assistant qt5-gtk-platformtheme qt5-qmake qt5-qmake-bin qt5-qmltooling-plugins qtbase5-dev qtbase5-dev-tools qtdeclarative5-dev qttools5-dev qttools5-dev-tools qttools5-private-dev remmina remmina-common remmina-plugin-rdp remmina-plugin-secret remmina-plugin-vnc rhythmbox rhythmbox-plugins samba-libs sane-utils simple-scan sip-dev ubuntu-desktop ubuntu-session ubuntu-software unattended-upgrades ure xdg-desktop-portal xdg-desktop-portal-gtk 升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 393 个软件包未被升级。
06-18
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

努力生活的黄先生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值