Tokens Builder in Python

Source: Internet
Author: User
Tags generator

Case: Tokens Builder Learning Essentials

--random

--string

--string and digital synthesis exercises

--List

Token generator Programming

Analysis:

import randomrandom.choice(‘acfhjlio‘)   #随机选择一个字符
‘f‘
str_list=[‘a‘,‘b‘,‘c‘,‘d‘,‘e‘,‘2‘,‘3‘]s = ""s.join(str_list)    #把列表中的字符串连接到s内,连接一起的意思
‘abcde23‘
s = ""for i in range(5):    s = random.choice(‘adfjlui‘)    print(s)
lidiu
import stringstring.ascii_lowercase     #表示26个小写字母
‘abcdefghijklmnopqrstuvwxyz‘
string.ascii_uppercase     #表示26个大写字母
‘ABCDEFGHIJKLMNOPQRSTUVWXYZ‘
string.ascii_letters      #表示所有字母
‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ‘

Instance:

import stringimport randomstr_from = string.ascii_letters + string.digitscount = 10tokens = []for i in range(count):    s = random.choice(str_from)    print(s)    tokens.append(s)"".join(tokens)
Npu3rHJ5D4‘Npu3rHJ5D4‘
Tokens Generator simplifies programming

Analysis:

[x for x in range(8)]
[0, 1, 2, 3, 4, 5, 6, 7]
[ random.choice(string.ascii_letters + string.digits) for x in range(5)]  #x被放弃的变量,只是占位,使random循环5次
[‘K‘, ‘2‘, ‘8‘, ‘a‘, ‘0‘]
[ random.choice(string.ascii_letters + string.digits) for _ in range(5)]
[‘u‘, ‘6‘, ‘W‘, ‘v‘, ‘j‘]

Instance:

import stringimport randomcount = 8str_from = string.ascii_letters + string.digitstonkens = [ random.choice(str_from) for _ in range(count)]"".join(tokens)
‘Npu3rHJ5D4‘

Tokens Builder in Python

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.