Python Basics Flashcards
After you create a string, can it be changed? Why?
No, because it is immutable.
Immutable
Impossible to modify
Why are there options to use either a double or single quote to make a string?
So that if the string contains either of those two characters, you wont unintentionally close the string early.
What is an escape sequence?
a character that tells the interpreter to read a character a certain way that may normally be reserved for specific syntax.
What are examples of escape sequences?
\n is new line
“”” tripple quotes also let you use both single and double quotes in a string
What is concatination?
use +, it will add two strings together. Remember to use proper spacing, if you dont include a space in a string, it wont show up.
What is in place addition?
+= It will append a string into a string already stored in a variable.
What function will tell you the length of a string?
len(var_name)
Everything that you create in python is an _____.
Object
What is a method?
An ability of an object. Or, functions that belong to an object.
How do you access methods that an object owns?
By using dot notation. E.g, there is a method called upper that converts all characters in a string to upper case, so you can say:
var_name.upper()
and the output will be all caps version of a string you called var_name
What is string formatting?
Allows you to create a re-usable template that can be filled with data. You include a set of curly braces (called a placeholder) in a string where you want to be able to insert data, then when you call the format function, you pass data in the parens in the order that they appear in the original string.
How do you find out if a string contains a part of a string?
in e.g. “pop” in “popcorn” returns True
What is a boolean value?
True or false
how do you cooerce a data type into becoming a boolean value?
bool()