2.2.2 Data Types Flashcards
What are the 4 data types?
Integer
String
Real/Float
Boolean
What is an integer?
Chain of characters eg. “Hello”
What is Real/Float?
Value with a decimal place eg. 10.5, 20.3
What is an integer?
Whole number eg. 10,20,30,40
What is Boolean?
Value that are either true or false?
What is casting?
Changing one data type into another
eg. str(25) change to str
int(“48”) change to int
Float(“10.5”) change to float
What is concatenation?
Joining string to each other
Ans=str(A)+B
Print(Ans)
Write a program that asks
name - str
age - int
height - float
subject - str
name = str(input(“please enter your name”))
age = int(input(“please enter your age”))
height = float(input(“please enter your height”))
subject =str(input(“please enter your favourite subject”))
print(“Hello there” + name + “you are” + str(age). “Your height is” + str(height) + “And your favourite subject is” + subject)
What is string handling?
upper()
lower()
title()
replace()
str = “Computer Science”
str.upper() = will convert string into uppercase
str.lower() = wil convert string into lowercase
str.title() = capitalise first letter of every word
str.replace(“C”,”P”) = Pomputer Spienpe
len(str) = Show number of characters in the string