Python Basics Flashcards
What is code that returns a value when evaluated ?
Expressions. For example, the code wage * hours * weeks is an expression that computes a number.
What is a variable ?
Variables are named references to values stored by the interpreter. Example: Wages, Salaries, Hours. These can hold specific values.
What is an assignment ? Describe the syntax used.
An assignment is how you create new variables in python. A new variable is created using the = symbol. With the varialbe name on the left and the value on the right. Example future_car = 720s.
How to display variables or expression values in python ?
print()
What is the comment syntax in python ?
#
What is the syntax to keep subsequent print statements on the same line ? How to keep this output on same line:
print(‘Hello world.’)
print(‘You’re gay.’)
end=’ ‘
print(‘Hello world.’, end=’ ‘)
print(‘You’re gay.’)
How to output a variable name ?
print(variable_name)
What is the syntax for a newline character ?
How would you print the number 2 on a newline given:
print(1, 2)
\n.
print(‘1\n2’)
How to assign variable favorite_car, to input take from the user ?
favorite_car = input()
How to convert strings to integers ?
Convert my_int = ‘123’ to an integer.
int()
my_int = int(‘123’)
How to assign variable_name to an integer input by the user with an included prompt.
variable_name = int(input(‘: ‘, ))
What are three things that every python object possesses ?
Type, value, identity
What is an objects mutability and what determines it ?
Mutability means whether or not the object’s value can be changed. This is determined by type.
How to print an object’s type ?
print(type(‘ABC’))
What is an object’s identity ?
A unique identifier that describes the object. It usually references the object’s memory address where the object is stored.
What are the data types that can be created using python ?
String, integer, float,
What is a combination of items, like variables, literals, operators, and parentheses, that evaluates to a value, like 2 * (x + 1)
Expression
A symbol that performs built in calculations ?
Give 5 examples.
Operator
+ - / * **