Python Basics Flashcards
What is running file in Jupyter?
A file is considered a running file until you shut it down
What is Jupyter?
Python allows you to communicate with the computer with the help of a specific software or application: Jupyter
It is a server-client application that allows you to edit your code through a web browser
It’s not a text editor that opens a new window everytime with different codes bits
Access and leave a cell
Enter + Escape
Execute line to output field
Ctrl + Enter
Can output line be modified?
No
Execute line to output field + new cell
Shift + Enter
Copy/Paste cells
Select cells (so no cursor appears in input)
With C, X and V you can copy, cut and paste
With arrow keys you can move up and down
Asterisk sign in input cell?
Can appear in the input cell –> Meaning the code takes too long
Can be stopped with the stop symbol in the viewport
Insert markdown cell
&
Convert cell from markdown to code cell and vice versa
M
Y
When using a capital in variable, for example Y instead of y, what will happen?
Will lead to an error
Assign values to x and y
x,y = (1,2)
Parentheses are not obligatory but is for readability
When you just want to print an output
print()
Number functions. Name 2
Int() –> Integer –> Will round of to integer value
float() –> Float –> Convert to decimal
With this function you can ask what type the variable is
type
How are booleans written?
Booleans need to be written in CAPITAL LETTERS
String variables how to write?
Use single or double quotes
When printing a string it will give the output without quotes
Convert number into text
str() function
Print number + text
print( str(x) + ‘Dollars’ )
Do you need to specify a variable type?
As opposed to other programming languages, Python can automatically guess the type of data you are entering –> It always knows the type of variable
When to use double quotes?
Best for working with strings since you can have single quote in your text
Two ways to add strings together
Plus sign
Trailing comma: print(‘Red’,’car’) > Will add a space
A way to include a quote in string
Backslash before the quote
What to do when 16/3 leads to ‘5’
Try:
float(16) / 3
or:
16.0
What to do when not having enough space in the line?
In that case you can use backslash \ to continue the line onto the next line without breaking the code
Difference = and ==
With = you can set a value
With == you can check if that value is true or false
What is returned: “Friday”[4]
‘a’
In Python we start from the 0 character and then start counting upwards
What to do when lines are part of a function?
When lines are part of a function you must apply indentation to it
Same goes vice versa
Indent goes with using tab
Give the order of operators for AND, NOT, OR
Order of operators
NOT
AND
OR
Example:
True and not True –> not True will be processed first
False or not True and True –> Leads to False
True and not True or True –> Leads to True because right part is True
What can be written instead of == and !=
is, and is not
What is used as elseif statement?
elif statement