Basics Flashcards

1
Q

Escaping characters: how do you stop an apostrophe in a work (like there’s) breaking your code?

A

Add in a backslash before the apostrophe, e.g. ‘This isn't flying, this is falling with style!’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you raise a number to the power of another number?

A

using two asterisks e.g. 3 ** 2 = 9

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

when counting the indices of a string in python, what number do you start from?

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

If x = 3 how would you tell the computer to print x?

A

print(x) [note the brackets are important]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a string? How do you create them?

A

Text. By enclosing characters in quotes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you make a string completely lower case?

How do you make a string completely upper case?

A

string. lower()

string. upper()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you turn a non string into a string?

A
using str() 
e.g. str(2) = "2"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Methods that use dot notation only work with strings?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the command len() do?

A

Returns the length (the number of items in an object)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What do each of these comparitors mean?

  1. (==)
  2. (!=)
  3. ()
  4. (>=)
A
  1. Equal to
  2. Not equal to
  3. Less than
  4. Less than or equal to
  5. Greater than
  6. Greater than or equal to
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a Boolean?

A

A data type that can only have two values True or False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the three Boolean operators and what do they do?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does % do?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you add an item to the end of a list?

A

using .append

e.g. nums = {1, 2, 3]
nums.append(4)
print(nums)

> > > [1, 2, 3, 4]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly