Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Python cheatsheet
- var = 3 #sets a variable to =3
- bool = True #sets a boolean to true (must be capitalized)
- float = 1.22 #sets a var but with decimals
- string = “Hello World”
- \ fixes characters that break strings, like ‘
- # makes a comment
- “”” sets a
- multi line comment”””
- exponents use ** instead of ^ #2**3=2^3
- string characters get numbered in an index which can be called with STRINGNAME[PLACE] and the place starts from 0
- len(stringname) returns the length of a string
- STRGINGNAME.lower( ) returns the string with caps lowered (does not edit the string)
- .upper( ) is anti .lower
- str(STRINGNAME) returns the string version of a non-string like a bool or var (turns 2 into “2”)
- strings can be added just like numbers
- print “Adding “ + “Strings”
- can’t add a string to a non-string so use str() to make things into strings
- also to add strings you can use %s and then after the quotes write % (stringname, stringname2)
- date and time library can be imported with the starting line "from datetime import datetime” and then used with datetime.now (can be printed or set as a string)
- year can be called with STRINGNAME.year (if STRINGNAME = datetime.now), same with month/day
- equals to ==
- not equal to !=
- less < less or equal <= and the opposite is more ofc
- and checks if both statements are True
- or makes sure at least one statement of them is true
- not gives the opposite of the statement
- if there’s several, not is checked first, then and, then or
- parentheses can be used to ensure the order you want is done tho
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement