Python Cheatsheet: Part I

Math Functions

import math
n = math.floor(1.5)
m = math.ceil(1.5)
k = abs(-19)

Input

string_data = input('Enter your data: ')
print(type(string_data)) # String

Formatting

# 0 & 1 are index of the parameters
text = "My planet is {0} in the {1}"
print(text.format('Earth', 'galaxy'))

String

text = "hello world! It's lovely 2019"
freq = text.count('lo')
print("freq={}".format(freq)) # freq = 2
- islower()
- isupper()
- lower()
- upper()
- isalpha() # spaces not allowed
- isdigit()
- isalnum() # alpha-numeric

Written with StackEdit.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.