Data types and variables Flashcards

1
Q

Define variable and identifier

A

Variable: Location in memory contains one or more data value

Identifier: Unique name given to variable, procedure, function, class or object

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

How does assignment happen

A

When the ‘=’ sign is used as a command

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

What are the 4 main datatypes and define them

A

Integer: Positive and negative whole numbers, includes zero
Float: Number with a decimal point
Boolean: True or False
string: Text

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

What are the 7 operators and define them

A

Addition (+) : Normal adding
Subtraction (-) : Normal subtracting
Multiplication (*): Normal multiplying
Division (/): Normal dividing
Indices (**): Powers
DIV (//): Integer division/quotient rounds down to nearest integer
MOD (%): Modulus also known as the remainder

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

Augmented assignment operators

A

+= —> same as x = x + 3
-= —> same as x = x - 1
*= —> same as x = x * 10
/= —> same as x = x/ 5
//= —> same as x = // 5
%= —> same as x = x % 7

Same as normal operators but uses less memory

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

Name different string manipulation

A
  1. variable.upper() - changes variable to upper case
  2. variable.lower() - changes variable to lower case
  3. variable.swapcase() - switches case of all characters
  4. variable.capitalize() - Capitalises first character in string
  5. variable.title() - Capitalises first character after every space
  6. variable.strip(chars) - Removes ‘chars’ from variable. If left blank removes leading white space
  7. variable.replace(old,new) - Replaces all old characters with new ones
  8. len(variable) - Returns number of characters
  9. variable[index] - Only character in index position is printed
  10. variable[start:end] - Only character in that specific range is printed. Includes the start does not include the end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly