Chapter 4 - Data types Flashcards
What is data?
information - the quantities, characters or symbols that operations are performed on by a computer, and which may also be stored and transmitted
What is an intiger?
Whole numbers both positive and negative ie 3
usually 1-4 bytes
What is a float AKA real numbers
All real numbers - decimals and integers
usually 4-10 bytes
What is a character
A single character
What is a string?
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
What is boolean?
true or false
What does a strongly typed language mean?
You must explicitly state the data type when creating the variable ie C or C++
What does a weakly-typed language mean?
The programming language “guesses” what data type should be used ie python
Fix this code (its python):
height A = input(‘Enter heightA’)
height B = input(‘Enter heightB’)
totalHeight = heightA + heightB
print(totalHeight)
height A = input(‘Enter heightA’)
height B = input(‘Enter heightB’)
totalHeight = int(heightA) + int(heightB)
print(totalHeight)
What does len(string) do?
counts number of characters
What does string.capitalize() do?
capitlises the first letter
What does string.lower() do?
Puts the whole string in lower case
What does string.upper() do?
Puts the whole string in upper case
What does string.rjust() do?
sets how far across the page the string is. ie “dog”.rjust(50)
= dog
What does string.replace(oldvalue,newcalue) do?
replaces a value with a new value