Strings and Variables Flashcards
”, ‘
Used to create a string
ex: “Hello”, ‘345’
\
Used to escape “ and ‘ when appropriate
ex: print(‘I/’m a cat’) –> I’m a cat
\n
Creates new line
ex: print(“Hello\nthere”) –>
Hello
there
\t
Creates tab
ex: print(“Hello\tthere”) –>
Hello there
”””
Automatically puts newlines when used in place of “ or ‘
ex: print(“"”Why,
hello there”””) –>
Why,
Hello there
Concatenation
Adding strings together
ex: print(“Spam” + “Eggs”) –> SpamEggs, print(“1”+”2”+”3”) –> 123
Strings can be multiplied by floats
False, only integers
=
Creates variable
ex: name = “Anna”
Python is a case sensitive languauge
True
What can be used as a name in Python?
Allowed: Letters, Numbers, Underscores
ex: this_is_a_normal_name = 7
You can start a name with a number
False
ex: 123abc = 7 –> “SyntaxError: invalid syntax”
You can reassign a variable as much as you want
True, though not good practice
input()
Function to get input from user
ex: x = input()
Even if the user enters a number as input, it is processed as a string.
True
input(“ “), input(‘ ‘)
Creates prompt message
ex: name = input(“Enter your name: “)