Day#3


Python for Beginners

How to print a multi line block in python?
| Three single quotes will print the multi line block

print('''My name is Orca
Kids also call me Killer Whale ''')

How to achieve randomization in python (Generate pseudo-random numbers)?

| using random module, import the random module.

| some most common and useful random functions :

import random
print(random.random())
print(random.sample())
print(random.seed())
print(random.getstate())
print(random.setstate())
print(random.randrange(start, stop, step))
print(random.randint())
print(random.choice(seq))
print(random.shuffle(x))
print(random.uniform(a, b))

How to get the previous state of random number?

| using random.getstate() function capture the current internal state of the random number generator. This state will be restored using random.setstate(state)

How to generate the same sequence of random numbers again and again?

| using random.seed() function . Intialize the random number generator with a seed value . example random.seed(38)


Leave a Reply

Your email address will not be published. Required fields are marked *