CS50 Notes

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

mistakes in program - bug, which are solvable.

minor details can cause bugs, which is what makes it frustrating, computers take
you literally.

return values, and variables: container for a value. Giving variables the value of
a return value.

comments, starts with # or ''' ''' can be used, a note that wont break your code.
also known as pseudocode, using human language to express your thoughts and
intentions of your code.

input without a specification sets it as a string as the default datatype.

print takes multiple arguements using a comma.

print(*objects, sep=' ', end='\n', file = sys.stdout, flush=False)

*objects, means the function can take an infinite number of objects


sep=' ', means
end ='\n', means new line, to indicate when you want the program to move to the
next line.
end ='' will connect two functions.
these are parameters in a function.
using a backslash before a quotation will take away its meaning and will use
printed as just a quotation.

f indicates a format string.


curly brackets in a f string,
= means assignment in python
.strip
.title
.capitalize
.split, splits the string input into different sections and will only return the
value of the specific desired section of the string.

interactive mode, writing code in the terminal to get immediate results of the
code.

integers.

you can put a function in a function for eg, int(input("woah this is cool"))
python, just like math does the inside parenthesis first then the outer
parenthesis.

its best to keep code simple, short and readable.

float: number with a decimal point, whereas int doesn't include decimals.

to add commas you have to use {} and use a colon.

def, indentation, the definition of a function must be in a line before the


function is used. it must exist before you use it.

scope, variable only existing in the context in which you defined it. since.

return, its used to literally return a value

.replace(), replaces a character for another desired character


.replace('replacing character', 'the new character you want')
loops:

while - way to express a loop.

computer scientists prefer to start counting from zero.

for -
list -

_ symbol indicates a variable, which wont be used later in the program, irrelevant

break - will break out of the most recently begun while loop, when the condition is
true of course.

while True:
x = int(input("whats x "))
if x > 0:
break

above code can be used to repeatedly ask for input if the user doesn't provide
certain input.

len, will provide the length of a list

dict, data structure that allows you to associate one value with another. Just
like a dictionary in the real world.

for loop

You might also like