Basics Flashcards
Escaping characters: how do you stop an apostrophe in a work (like there’s) breaking your code?
Add in a backslash before the apostrophe, e.g. ‘This isn't flying, this is falling with style!’
How do you raise a number to the power of another number?
using two asterisks e.g. 3 ** 2 = 9
when counting the indices of a string in python, what number do you start from?
0
If x = 3 how would you tell the computer to print x?
print(x) [note the brackets are important]
What is a string? How do you create them?
Text. By enclosing characters in quotes
How do you make a string completely lower case?
How do you make a string completely upper case?
string. lower()
string. upper()
How do you turn a non string into a string?
using str() e.g. str(2) = "2"
Methods that use dot notation only work with strings?
True
What does the command len() do?
Returns the length (the number of items in an object)
What do each of these comparitors mean?
- (==)
- (!=)
- ()
- (>=)
- Equal to
- Not equal to
- Less than
- Less than or equal to
- Greater than
- Greater than or equal to
What is a Boolean?
A data type that can only have two values True or False.
What are the three Boolean operators and what do they do?
and - checks if both the statements are true
or - checks if at least one of the statements are true
not - gives the opposite of the statement
What does % do?
It is used to find the modulus of two integers. For example 10 % 4 would divide 10 by 4 and return a remained of 2
How do you add an item to the end of a list?
using .append
e.g. nums = {1, 2, 3]
nums.append(4)
print(nums)
> > > [1, 2, 3, 4]