“string acak python” Kode Jawaban

string acak python

import random
import string

def random_string_generator(str_size, allowed_chars):
    return ''.join(random.choice(allowed_chars) for x in range(str_size))

chars = string.ascii_letters + string.punctuation
size = 12

print(chars)
print('Random String of length 12 =', random_string_generator(size, chars))
VasteMonde

Cetak string acak dari daftar python

import random

list = ["Item 1", "Item 2", "Item 3"]			# List
item = random.choice(list)						# Chooses from list
print(item)					# Prints choice

# From stackoverflow
# Tried and tested method
Fair Finch

string acak python

import secrets 
secrets.token_hex(nbytes=16)

# this will produce something like 
# aa82d48e5bff564f3221d02194611c13
Danny Mor

menghasilkan python string acak

import string
import random

length=5
#python2
randomstr = ''.join(random.sample(string.ascii_letters+string.digits,length))


#python3
randomstr = ''.join(random.choices(string.ascii_letters+string.digits,k=length))

                                  
Worrisome Wallaby

cara membuat modul yang menghasilkan huruf acak dalam python

# -random letter generator-
import string
var1 = string.ascii_letters

import random
var2 = random.choice(string.ascii_letters)
print(var2)
Scary Sandpiper

Cara menghasilkan string acak dalam python

import random
import string

# printing lowercase
letters = string.ascii_lowercase
print ( ''.join(random.choice(letters) for i in range(10)) )

# printing uppercase
letters = string.ascii_uppercase
print ( ''.join(random.choice(letters) for i in range(10)) )

# printing letters
letters = string.ascii_letters
print ( ''.join(random.choice(letters) for i in range(10)) )

# printing digits
letters = string.digits
print ( ''.join(random.choice(letters) for i in range(10)) )

# printing punctuation
letters = string.punctuation
print ( ''.join(random.choice(letters) for i in range(10)) )
DreamCoder

Jawaban yang mirip dengan “string acak python”

Pertanyaan yang mirip dengan “string acak python”

Lebih banyak jawaban terkait untuk “string acak python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya