This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
python_reference [2013/06/01 14:05] sandeep created |
python_reference [2018/03/24 11:13] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Python Reference ====== | ====== Python Reference ====== | ||
===== String Reference ===== | ===== String Reference ===== | ||
+ | [[http://docs.python.org/2.7/library/string.html|Click here for Python String Docs]] | ||
==== String Reverse ==== | ==== String Reverse ==== | ||
<code python> | <code python> | ||
Line 8: | Line 9: | ||
</code> | </code> | ||
+ | =(or)= | ||
+ | <code python> | ||
+ | myString = "Hello World !" | ||
+ | reversedString = myString[::-1] # Gets the reverse string | ||
+ | </code> | ||
+ | |||
+ | ===== Others ===== | ||
+ | ==== Random ==== | ||
+ | [[http://docs.python.org/2.7/library/random.html?highlight=random#random|Python Random Docs]] | ||
+ | <code python> | ||
+ | import random | ||
+ | myRandomNumber = random.randrange(1,10) # Returns a random number between 1 and 10 | ||
+ | </code> | ||
+ | |||
+ | <code python> | ||
+ | import random | ||
+ | numbers = range(100) | ||
+ | random.shuffle(numbers) # shuffles the list | ||
+ | print(numbers) # random numbers from 0 to 99 | ||
+ | </code> | ||