1/55
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
print ()
displays text
Why must the text in the print() function be enclosed in quotes?
so the interpreter identifies it as a string
string
sequence of characters; can include letters, numbers and symbols
True or false: arithmetic expressions can be performed within a print() command
true
True or false: arithmetic expressions inside the print() function must be enclosed in quotes
false
comments
short notes placed in different parts of the program, explaining how those parts of the program work; started by the # symbol and ignored by the interpreter
guidelines for comments
should be clear and concise
don’t comment on things that are self-explanatory
update comments as the code evolves
use comments to explain logic
variable
a container for storing data values (e.g. strings or numbers)
created and assigned using “=”
can consist of alphabets, digits, and underscores
cannot have special symbols and cannot begin with a number
camelCase
the variable name begins with lowercase letters, and the first character of the second and subsequent words is written in uppercase
snake_case
underscores replace spaces in separating words in variable names
How can you display multiple items with one print statement?
by separating the items with commas
data types
categories of values in memory
int
value written as a whole number without a decimal point
float
value written with a decimal point
str
sequence of characters
input()
used to read a line of input from the user; usually displays a prompt message to guide the user on what information to provide
What data type does the input() function always return?
string
What built-in functions can be used to convert between data types?
int(item) - converts to integer
float(item) - converts to float
What does the item have to be for type conversion to work?
a valid numeric value
%
remainder
**
exponent
True or false: the Python interpreter followers order of operations
true
How can you break a statement into multiple lines?
using backslash (\)
hard-coding
storing values in variables that are not dependent on user input
makes the code hard to change
good for learning but not for applications
multiple assignment
assigning values to multiple variables in a single statement
What does combining different data types in a print statement require?
converting one type to another
f-string (formatted string literal)
allows you to embed expressions directly inside strings
gives a more flexible and readable output format that using the str() function
f-string format
print("‘{<index>:<padding character><alignment character><block size><precision>}’)
What does it mean for a string to be immutable?
it cannot be changed after creation
string concatenation
combining strings using the + operation
ex: greeting = “Hello” + “ “ + “World”
escape sequence
a sequence of characters that when used inside a character or string, is converted into another character or series of characters that may be difficult or impossible to express directly
\’
single quote
\\’
double quote
\\
backslash
\n
newline
\r
carriage return
\t
horizontal tab
\b
backspace
\v
vertical tab
\0
null character
index
position of a character inside a string
What does indexing start at for the first character?
0
What symbol do you use to access a character at a specific index?
square brackets [ ]
negative indexing
accessing characters from the back end of the string
string slicing
allows you to obtain a substring by specifying a range of indices
string slicing format
string [start:stop]
start is inclusive
stop is exclusive
str.lower()
converts all characters to lowercase
str.upper()
converts characters to uppercase
str.strip()
removes leading and trailing whitespace
str.split()
splits the string into a list of substrings
str.join(iterable)
joins elements of an iterable to a single string
str.replace(old, new)
replaces occurrences of a substring
str.find(sub)
returns the lowest index of the substring
str.startswith(prefix)
checks if the string starts with a prefix
str.endswith(suffix)
checks if the string ends with a suffix
len(obj)
returns the length of an object