Skip to main content

A simple utility library for string and number manipulation

Project description

simple_utils_demo41011

一个简单实用的Python工具库,提供常用的字符串和数字处理功能。

功能特性

StringUtils

  • 字符串空值检查
  • 驼峰命名法转换
  • 下划线命名法转换
  • 字符串截断
  • 字符串重复
  • 子字符串计数

NumberUtils

  • 奇偶性检查
  • 质数判断
  • 数值四舍五入
  • 数值范围限制
  • 计算平均值
  • 数字各位求和
  • 数字格式化

安装

使用pip安装:

pip install simple_utils_demo41011

使用示例

StringUtils

from simple_utils import StringUtils

# 检查字符串是否为空
print(StringUtils.is_empty(""))  # True
print(StringUtils.is_empty("  "))  # True
print(StringUtils.is_empty("hello"))  # False

# 驼峰命名转换
print(StringUtils.to_camel_case("hello_world"))  # helloWorld

# 下划线命名转换
print(StringUtils.to_snake_case("HelloWorld"))  # hello_world

# 字符串截断
print(StringUtils.truncate("This is a long text", 10))  # This is ...

NumberUtils

from simple_utils import NumberUtils

# 检查奇偶性
print(NumberUtils.is_even(4))  # True
print(NumberUtils.is_odd(5))  # True

# 检查质数
print(NumberUtils.is_prime(7))  # True

# 数值四舍五入
print(NumberUtils.to_rounded(3.14159, 2))  # 3.14

# 数值范围限制
print(NumberUtils.clamp(15, 0, 10))  # 10

# 计算平均值
print(NumberUtils.average([1, 2, 3, 4, 5]))  # 3.0

许可证

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple_utils_demo41011-0.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_utils_demo41011-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file simple_utils_demo41011-0.1.0.tar.gz.

File metadata

  • Download URL: simple_utils_demo41011-0.1.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.4

File hashes

Hashes for simple_utils_demo41011-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d80025cccddff26596ed6054e92cdf537430d7d2bdfb9aa83d5006c458f852d8
MD5 9b2f38ed90cb5654f2d63ff33ca7cf41
BLAKE2b-256 1df885eb4d9cbfebb3a1f6655c7a59dac4769a575d90f3aa29cb72c4d16b6479

See more details on using hashes here.

File details

Details for the file simple_utils_demo41011-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_utils_demo41011-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d71c6b436ef38a79a0d518601ce5c1961a71a91d97290bdf4966be976b973bb
MD5 eff4fd4664f1e3e629bee4f5aa97b7a4
BLAKE2b-256 9955beb9ddcc6b1cf4d7dcf8437a620255d4f77c9c3670d5dda9edf5a845f3d8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page