Lessons 1 & 2 Flashcards
What is a program?
a list of instructions for manipulating numbers or other symbols
What is a computer?
a device that can follow the instructions in a program and carry out the manipulations
What is the assignment operator in python?
=
Define assignment operator
functions to assign a specific value to a variable
What is the syntax for exponentiation?
**
Define variable
can be thought of as a label for a container than refers to some kind of data or other info stored in a computers memory
What are the containers that refer to some kind of data/info in a computers memory?
objects
math defines a _____ for the functions in the math module
namespace
how do you use ln in python?
import math
a = math.log(10)
What is the class of values that are strings of text characters called?
strings
How do you catenate two strings?
by using the * operator
How do you determine what data type a variable is?
type(variable_name)
What is an integer?
A number without a decimal
What is a float?
A floating point number has a decimal
What does a kernel do?
keeps track of variables and their assigned values and other info that defines the state of the notebook at any point
String function
converts a numeric value (integer or float) to a string; str(5)
Integer function
converts string to integer; int()
Float function
converts strings representing numbers to floating point numbers; float(‘string’)
What element of a string would strng[0] return? strng[1]?
first element; second element
Extracting a subset of a string (or other multi-element object) is referred to as_____ and the result is called a _____
slicing; slice
In a slice, the first number is the index of the _____ element in the substring; the second number in the brackets is _______
first; one more than. the index of the last element in the substring
The last element in a string is identified by ____
-1
negative step parameter
the slice will be returned in the reverse order
The second parameter in a slice specifies
the element following the last element to be returned using the original numbering
upper method
converts lowercase characters to uppercase; my_string.upper()
find method
a string method that requires an argument; the argument is a search string and the returned value is the first location in the string object at which the search string is found
find method using more than one argument
can take up to two optional integer arguments, following the string argument, to specify the region of the string to search
the second argument specifies the index of the position immediately following the the region to search
the indexes are separated by commas
count method
requires a single string argument and can accept two optional integer arguments to specify to the scope of the search
replace method
requires two input string arguments
searches the string to which it is applied for occurrences of the first argument and returns a new string with all the occurrences replaced with the second string argument
my_string.replace(‘Fred’, ‘Joe’)
len function
not specific to strings.
a function that returns an integer that represents the number of characters in a string
len(my_string)