Chapter 4 - Data types Flashcards

1
Q

What is data?

A

information - the quantities, characters or symbols that operations are performed on by a computer, and which may also be stored and transmitted

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

What is an intiger?

A

Whole numbers both positive and negative ie 3
usually 1-4 bytes

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

What is a float AKA real numbers

A

All real numbers - decimals and integers
usually 4-10 bytes

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

What is a character

A

A single character

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

What is a string?

A

Multiple characters ( a list of characters ). A char can be a string, but a ( multiple - character ) string cannot be a char.
Typically 1 byte per character

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

What is boolean?

A

true or false

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

What does a strongly typed language mean?

A

You must explicitly state the data type when creating the variable ie C or C++

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

What does a weakly-typed language mean?

A

The programming language “guesses” what data type should be used ie python

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

Fix this code (its python):
height A = input(‘Enter heightA’)
height B = input(‘Enter heightB’)
totalHeight = heightA + heightB
print(totalHeight)

A

height A = input(‘Enter heightA’)
height B = input(‘Enter heightB’)
totalHeight = int(heightA) + int(heightB)
print(totalHeight)

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

What does len(string) do?

A

counts number of characters

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

What does string.capitalize() do?

A

capitlises the first letter

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

What does string.lower() do?

A

Puts the whole string in lower case

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

What does string.upper() do?

A

Puts the whole string in upper case

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

What does string.rjust() do?

A

sets how far across the page the string is. ie “dog”.rjust(50)
= dog

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

What does string.replace(oldvalue,newcalue) do?

A

replaces a value with a new value

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

What does string.split(separator) do?

A

Splits the string at a point

17
Q

What does string.strip(characters) do?

A

Gets rid of characters stated

18
Q

What does string.join(list) do?

A

makes it into a list

19
Q

What does string.find(substring) do?

A

used to find the first occurrence of a sub-string in the specified string being called upon.

20
Q

What does string.format(items) do?

A

he {0} in the format string is a format item. 0 is the index of the object whose string value will be inserted at that position.

21
Q

What does \n do?

A

Newline

22
Q

What does \t do?

A

tab

23
Q

What does " do?

A

prints quote mark

24
Q

What does \ do?

A

print backslash

25
Q

demoStr = “Mr Reed is an awesome teacher!”
demoStr[3:9]

A

Reed i

26
Q

demoStr = “Mr Reed is an awesome teacher!”
demoStr[-8:-1]

A

teacher

27
Q

demoStr = “Mr Reed is an awesome teacher!”
demoStr[:3] + demoStr[22:]

A

Reed teacher!

28
Q

Combining strings is called what?

A

Concatenation

29
Q

What can you use index positions to perform?

A

String traversals iterating through a string to perform tasks

30
Q

Can you give an example code of string traversals

A

demoStr = “Mr Reed is an awesome teacher!”
for char in demoStr:
if char == “a” or char == “e”
print(“Bingo!”)

31
Q

Since python starts counting index positions from 0, the first character in a string has position …… , meaning that the length of a string is ……….. than the index of it’s final character.

A

zero
one more