This page provides syntax for different data types in Python as well as some of their associated functions. Each section includes an example to demonstrate the described syntax or function.
A string is a sequence of one or more characters (index values start at 0)
Action | Function |
---|---|
Input:
Output:
W3 Schools: Python Strings
get word length
len("abc")
extract nth character from word
"abc"[n]
extract substring nth-mth character from word
"abc"[n:m]
search for character in word
"abc".index("character")
search for subword in word
"ab" in "abc"
remove white spaces from the end of a word
"abc ".strip()
remove last character from word
"abc"[:-1]
determine data structure type
type("abc")