commands and what they do Flashcards
int
integers; they are whole numbers | Ex: 14, 7, 241
float
floating point #s: they are numbers with a decimal point | Ex: 2.8, 7.6, 100.8
str
strings; these are an ordered sequence of characters or numbers within quotes | Ex: “hola”, “yellow”, “example”
list
lists; an ordered, changeable sequence of objects | Ex: [“hola”,7,2.8]
dict
dictionaries; unordered Key:Value pairs | Ex: {“key”:”value”,”name”:”Jose”}
tup
tuples; ordered unchangeable sequence of objects | (7.6,”yellow”,241)
set
sets; unordered collections of unique objects | {2.5,”example”,(2,3,5)}
bool
booleans; logical value that indicates True or False
\n
Puts the following string on a new line when printed
\t
Inserts a tab
len()
Returns the length of the string entered in the parentheses
str.upper()
Outputs everything in the string as uppercase
str.lower()
Outputs everything in the string as lowercase letters
str.split()
Outputs the string in a list as specified by the splitting condition typed into the parentheses | by default it splits by any white spaces in the string
%s
Inputs a specified string into the spot the function was placed: will convert whatever is specified into a string
%r
Converts whatever is specified into a string representation using the repr() function
%d
Converts whatever number was specified into an integer
//
Floor division operator. It will truncate the decimal numbers off and output the integer
%5.2f
The 5 is the minimum number of integers the number will contain… If it’s less then a space will fill the spot. The .2f is the number of decimal places you’d like the
.format()
Will input into a print function what is entered into the parentheses. To put the placeholders in the print function, use {}
Formatted string literals | f-strings
Place f into print function right before the double quoted sentence. Insert the variable name into {}
Use !r right before typing variable name to get the string representation
elif statement
After declaring an if statement, you can write as many elif statements to state other conditions
else statement
After declaring if and all elif statements, you finish up with an else statement that’s a catch all for any condition not declared in the if/elif statements
break
Breaks out of the current enclosing loop
continue
Goes to the top of the closest enclosing loop
pass
Does nothing at all