Python Notes Flashcards
Is python case sensitive and does spacing matter?
yes to both
What is Print used for?
To show a value
Arithmatic in python?
+, -. *, /
Addition, subtraction, multiplication, division
**?
Does number to the power of a other
what does % do?
Gives remainder from a division
//?
Divides one number by another but rounds down to nearest integer
(still rounds down even when negative)
how to assign closely related variables?
x, y, z = 2, 3, 4
Can you have spaces in variable names?
no, should use underscores and all lower case
what is += used for?
Telling a descriptive value it is being effected by new values
also -= when want to subtract values
Float?
Decimal answer (even if it .0
Int?
Integer (whole number)
How to find out if int or float?
Use type()
Interaction with an int and a float always =?
Float
Can also use int and float as functions to add or remove decimal points
x = int(4.7) # x is now an integer 4
y = float(4) # y is now a float of 4.0
What does bool (boolean) do?
Say if something is true or false
Comparison operators?
< less than
> greater than
<= less or equal than
>= greater or equal than
== equal to
!= not equal to
What is a string?
Data type for immutable ordered sequences of characters
How to print words?
Use Print (“…….”)
How to get rid of issue of using speech marks within a quote?
Use single for overall one, and use double for quote
If need more than one, use a / before the ‘ to let python know its part of the string
How to combine, or repeat strings or put a space?
+ for combine
- for repeat
” “ for space
what does Len( ) do?
Returns the length of a string
How to convert values into a string value?
str()
How to convert values into a integer?
Int()
What is a method?
A function that belongs to an object
for example title() will turn the string into a title so capitals in each words
Is placed in the bracket and doesn’t need anything in its own brackets, acts on the string