1/25
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
What do variables have to start with?
either a letter or an underscore - can’t start with a number and ARE case sensitive
To make comments (make a code inactive), then…
Add a hash, which is cmd + /
What does % do?
gives remainder of first no. divided by second number
equal to and not equal to
“==” is equal to, “!=” is not equal to
“ifand” function
same as excel, just use “and” with spaces. Same with “or”
“not” used to..
flip a condition you’re checking
Not function example
Print(not(10 < 5 or 13 < 25)) ==> ans is FALSE
If you want to connect two things (like a no. to “sales”), use…
5 = “whatever”
How is a list defined? (what brackets?)
Square brackets [ ]
how would I print the length of my list? (after creating a list, for example [0, 1, 2, 3, 4, 5])
print(len(mylist)
Finding a specific character in your list (remember that indexes and lists start from zero)
print(mylist[2]) - would return 2 if starts from 0
strings vs sequences
strings are also sequences, but can’t be changed once created
How do I return just part of my sequence?
Slice - print(mylist[1 : 4 : 1]) … means print from characters 1 to 4 at a step of 1 character
Trick to reverse sequence
print(mylist[ : : -1])
Tuple
Used to hold data that won’t change (immutable)
How are sets defined? (what brackets)
Curvy brackets! { }
Rules for sets
Can only contain unique values, and repeated numbers won’t print more than once
What does “in” test for?
Tests for membership (whether something is in the list or not)
“in” example
print(1 in mylist) ==> returns TRUE/FALSE
What is the purpose of using mydict
if you do “mydict = {“one” : 1, “two” : 2, 3 : “three”, 4 : “four”}” then you connect pieces of data to “key” values
how to print using mydict
print(mydict[“one”]) returns 1
which values come first and second, values or keys?
Keys first, values second
Can “if” be used in a print statement?
Yes! ==> if x < y : print(“x is less than y”)
How can I created a statement that will return an answer for “if x<y, then say this, but otherwise, say this!”
“x less than y” if (x<y) else “x > or = y”
How do I indent?
Press tab (or insert 4 spaces)
What’s the point of indentation?
indentation is how the computer knows which lines of code belong together