Python 隨機字符串 (Generate a random string using Python)

Python · 02-10 · 67 人浏览
Python 隨機字符串 (Generate a random string using Python)

这个随机字符串由大小写字母和数字组成,长度为10。(This random string composed with 10 uppercase or lowercase letters and digitals)

def generate_random_string(length):
    characters = string.ascii_letters + string.digits  # 包含大小写字母和数字的所有字符(Include all possible uppercase or lowercase letters and digitals)
    return ''.join(random.choice(characters) for _ in range(length))

# 指定生成字符串的长度 (Custom the length of the string)
length = 10
# 生成随机字符串 (Generate a random string and assign it to a variable)
random_string = generate_random_string(length)
本站立足于美利堅合衆國,請讀者自覺遵守當地法律!如有違規,本站不承擔任何法律責任! This site is based in the United States of America, readers are requested to abide by local laws! If there are any violations, this site does not bear any legal responsibility! Theme Jasmine by Kent Liao