Skip to content

Instantly share code, notes, and snippets.

@karlpokus
Created November 23, 2015 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karlpokus/3d30f6272742b9d39b6d to your computer and use it in GitHub Desktop.
Save karlpokus/3d30f6272742b9d39b6d to your computer and use it in GitHub Desktop.
python API
# http://thepythonguru.com/
# start
$ python3
# end
$ exit()
# run
$ python script.py
# user input
$ name = input("Enter your name: ")
# str to int
$ int("string")
# check type
$ type([])
# import modules
import module_name_1, module_name_2
# immutable strings
$ id("string1")
# STRINGS
# char in string
$ "mango"[0]
# slicing strings
$ "mango"[1:3]
// "an"
# length of string
$ len("string")
# check existance of string in string
$ "pappa" in "barbapappa"
// true
$ "foo" not in "barbappapa"
// true
# loop
for i in "string":
print(i)
# METHOD NAME METHOD DESCRIPTION
isalnum() Returns True if string is alphanumeric
isalpha() Returns True if string contains only alphabets
isdigit() Returns True if string contains only digits
isidentifier() Return True is string is valid identifier
islower() Returns True if string is in lowercase
isupper() Returns True if string is in uppercase
isspace() Returns True if string contains only whitespace
endswith(s1: str): bool Returns True if strings ends with substring s1
startswith(s1: str): bool Returns True if strings starts with substring s1
count(substring): int Returns number of occurrences of substring the string
find(s1): int Returns lowest index from where s1 starts in the string, if string not found returns -1
rfind(s1): int Returns highest index from where s1 starts in the string, if string not found returns -1
capitalize(): str Returns a copy of this string with only the first character capitalized.
lower(): str Return string by converting every character to lowercase
upper(): str Return string by converting every character to uppercase
title(): str This function return string by capitalizing first letter of every word in the string
swapcase(): str Return a string in which the lowercase letter is converted to uppercase and uppercase to lowercase
replace(old, new): str This function returns new string by replacing the occurrence of old string with new string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment