How to create a string of N characters in one line of code with Python

2 Answers

0 votes
N = 10

s = "a" * N
 
print(s)
 
 
 
'''
run:
 
aaaaaaaaaa
 
'''

 



answered Sep 17, 2023 by avibootz
edited Sep 17, 2023 by avibootz
0 votes
import random, string

N = 10

s = ''.join(random.choices(string.ascii_lowercase, k = N))

print(s)



'''
run:

ecripknjej

'''

 



answered Sep 17, 2023 by avibootz

Related questions

2 answers 214 views
2 answers 366 views
1 answer 148 views
1 answer 198 views
...