Sunteți pe pagina 1din 3

Cheat Sheet:

Symbols:
+ add
- subtract
* multiply
// divide (whole number)
/ divide (can be a decimal number)
< less than
> more than
<= less-than-equal (the value on the left of the sign is smaller than, or equal to,
the value on the right).
>= more-than-equal
% modulus (not percentage)- the remainder after dividing. For example, 100/16=
6 remainder 4: 4 is the modulus.
!= Not equal to
== equal to
= used when defining a variable.

General Rules:

At the start of each string, after the >>>, you have to put print with a lowercase
p.
On the python shell mode, you cant leave lines out: everything has to be line after
line. To be able to skip lines and have paragraph written together, you will have to
open another window.
File, New File
Type in your code or message using variables or anything else you want.
Save the file.
Press f5, showing the message/code on the main shell mode.

Int- input will be an integer


Concatenation- using variables in a print statement. / Joining string.
String= a sequence of characters, which is immutable (once it is defined it
cant be reversed or changed)
If you want to add integers into the sentence, you have to change them into
string- put +str before the value.
input(Enter a number between 0 and 10 ) 2 and 4- this will output
24 because no int- not understood as numbers so not technically added.
Integers= whole numbers
float =used when dealing with decimals.
Iteration- when something gets repeated (loop).
1. Condition Control= while (gives a condition to fulfil).
2. Count Control= for (gives a range of numbers where to start the program
and stop, and the intervals of how the number will
change).
for x in range structure of count control / is used for iteration when
wanting to output results for a problem, with multiple numbers (in the
range).

Range (3, 31, 1)= the first number is where the loop will start.
= the second is where the loop will end (+1, so it would
end at 30)
This is the Boolean condition. If it is true
the code will run.

Structure of a while loop

\n starts a new paragraph

String methods:
Lower() - all the letter are outputted as lower case.
upper() - all of the letters are outputted as upper case.
title() - the first letter of each word turns capital (like in a title).
swapcase() - the letters that were inputted capital are lowercase, and those lowercase
are now capital.
Capitalize() - the first letter is capitalized.

Operands:
day += 1 - shortcut of (day = day+1)- you dont have to repeat day.

Operator Example Is Equivalent to


*= K*=5 K=K *5
/= k/=5 K=k/5
%= K%=5 K=k%5
+= K+=5 K=k+ 5
-= K-=5 K=k-5

print ("Shaking \n" * 4) - since *4 is not in the speech marks, what is in the speech
marks will be outputted 4 times.

Nested loop - count = 1


for tortilla in (0,1): For is inside
for chicken in (0,1): the for.
print("#", count)
print ("\t\t",tortilla, "\t\t", chicken)
count =count+1

Import random allows the computer to generate random numbers where wanted
{random.randint(1, 100)}
Import time allows times breaks between code {time.sleep(1)}.

SOMETIMES REPEAT THE CODING AT BEGINNING AND END!!!
Lists


Lists square brasckets/start at 0.
List.append adds value to list.
List.insert(1, item) adds item to a specific place in the list.
List.count(Jan) how many times it appears in list
List.remove(Jan)- removes
Len(list)- length of the list.
List.reverse()- reversezs the oder of the list.
List.sort() sorts the list alphabetically
In searches for something in the list.

S-ar putea să vă placă și