What is a string?
1 or more characters enclosed in speech marks
How do u write a print statement?
print(“…”)
What does concatenate mean?
Combining multiple strings into a single string
How to concatenate?
Using +
Eg. print(“…”+”…”)
U can also put variables in there, not just strings
Eg. print(“….”+ … + “…”)
What is an integer?
A whole number, called int
What is a floating point/real?
A number with a decimal, called float
What is mod?
Returns the remainder using the % symbol
Eg. 17%6=5
What is div?
Gives the integer number without rounding
does not show the remainders or decimals
Uses the symbol //
Eg.17//6=2
How to round numbers?
Eg. Round 17/6 to 3 decimal places
Use round(… , the amount of decimal places)
Eg.result = 17/6
round(result, 3)
How to say less than or equal to?
<=
How to say greater than or equal to?
> =
How to say not equal?
!=
How to say equal to?
==
What’s the difference between = and ==
= is for assigning a value
== is for comparing the 2 values either side
What is a variable?
A memory location that stored values which can change during execution
Eg. name=“Diya”
It can not start with a number, nor can it have a space
How to use , ?
It is used to separate separate strings, integers, real numbers and variables
Just remember to only add “ “ when u are talking about strings and not for variables or numbers
Eg. cost = 15
print (“The cost is £”, cost)
Can u use both + and , to concatenate?
Yes
But remember + can not be used as a separator and join a string and number so u have to turn numbers into strings
Eg.cost =15
price(“The cost is £ +str(cost))
How to make a string appear in a new line in just 1 print statement?
Use \n
Eg. print(“hello \nhow are you?”)
What does tab do?
Leaves a lot more space between the strings
Use \t
Eg. print(“hi \t how are you?)
How to make 2 strings that are not on the same line appear in 1 line?
By using end = “ “
Eg. print(“this should all print”, end = “ “)
print(“on the same line”)
How to make multiple strings that are not on the same line appear in 1 line?
U can either close all the separate strings and add a ,
Eg. print(“how will this”,
“statement”,
be printed?”)
Or u can add \ without closing the quotes
Eg. print(“This is a long line of text \
split in the middle of the quote”)
What does triple quotes do?
Retains the formatting of the string
Eg.print(‘’’
John Smith
23 Elm Street
Andover
‘’’)
This makes sure it is printed out exactly like it looks in the top (in between the quote marks obviously)
How do u write an input statement?
By using input(“ if there’s something u wanna say to the person typing in the input:”)
Eg. name= input(“Please enter your name:”)
print(“My name is”, name)
Or u can print the thing u wanna say first and then say variable=input()
Eg. print(“Please enter your name:”)
name = input()
Can u use + to separate variables or numbers to strings when writing an input statement?
Yes (remember to turn numbers into strings tho)
Eg.name= input(“Please enter your name:”)
print(“My name is”, name)
number= input (name, + “,” + “please enter your phone number:”)