Python 3 Flashcards
What are the four rules to naming variables?
- Variables are case sensitive.
- Variable names must be one word.
- Variable names may be letters, numbers, or underscore.
- Variable names cannot begin with a number.
Variables should begin with a ________ word, and multiple words should be separated with _________s.
lowercase , underscore
How do you assign an integer to a variable?
variable = integer x = 100
How do you assign a string to a variable?
variable = 'string' x = 'wes'
How do you print a variable?
print(variable)
print(x)
How do you assign multiple values to the same value?
variable1 = variable2 = variable3 = integer x = y = z = 0 x = y = z = 'wes'
How do you assign values to several different variables within the same line?
variable1, variable2, variable3 = value1, value2, value3
x, y, z = 1, ‘two’, 3
What is a global variable?
A global variable exists outside a function.
What is a function?
A function is a block of instructions that performs an action and, once defined, can be reused. Functions make code more modular, allowing you to use the same code over and over again.
What is a local variable?
A local variable exists within a function.
What is the python function to return an absolute value?
abs ( )
What are the five python data types?
- Numbers
- String
- List
- Tuple
- Dictionary
What are the three python numerical types?
- Integer
- Float
- Complex
What is the code to print the first letter in a string?
print(stringname[0])
What is a list?
A list contains items separated by columns and enclosed with brackets.